Reputation:
Can't find how to restart postgresql on OS X using command line in order to apply changes in pg_hba.conf. I'v tried various command from web and docs. How to do it right?
EDIT:Response of attempt to find the path looks this way:
TheKotik 73454 0.0 0.0 2619360 804 ?? S 7:20PM 0:01.57 /Applications/Postgres.app/Contents/Versions/9.6/bin/postgres -D /Users/TheKotik/Library/Application Support/Postgres/var-9.6 -p 5432
Upvotes: 57
Views: 102718
Reputation: 9485
Adapted from above answers and comments:
Find which version of postgres brew is running using:
brew services list
then run restart by appending the version:
brew services restart postgresql@15
Upvotes: 5
Reputation: 788
Switch over to the postgres account on your machine by running the following command:
sudo -i -u postgres
Then restart with:/Library/PostgreSQL/{version}/bin/pg_ctl -D /Library/PostgreSQL/{version}/data restart
Upvotes: 3
Reputation: 35
For mac
sudo -u postgres /Library/PostgreSQL/15/bin/pg_ctl -D /Library/PostgreSQL/15/data restart
Worked for me.
Upvotes: 2
Reputation: 9407
If you want to ensure you are restarting your correct Postgres version (e.g. version 15) AND your Postgres is not installed as a Service, then you can use the pg_ctl command and specify your data directory. Where is your data directory? Do the following:
% psql
viglione=# SELECT name, setting, context FROM pg_settings WHERE category = 'File Locations';
name | setting | context
-------------------+-------------------------------------------------+------------
config_file | /opt/homebrew/var/postgresql@15/postgresql.conf | postmaster
data_directory | /opt/homebrew/var/postgresql@15 | postmaster
external_pid_file | | postmaster
hba_file | /opt/homebrew/var/postgresql@15/pg_hba.conf | postmaster
ident_file | /opt/homebrew/var/postgresql@15/pg_ident.conf | postmaster
(5 rows)
I like to project the context column to reaffirm the settings that do require restart. If the value is postmaster, then you must use pg_ctl restart
and not pg_ctl reload
. Note the data_directory in row two. We can then specify that as an option to pg_ctl restart. First exit psql and then run the command at the OS level (note since in my case I am using homebrew package manager, i wouldn't use this option):
viglione# \q
% pg_ctl restart -D /opt/homebrew/var/postgresql@15
Given I am using homebrew, which is a system service, I would use this option:
% brew services restart postgresql@15
Upvotes: 2
Reputation: 329
For PostgreSQL 13.4 running on macOS Catalina 10.15.7, I had a different location for my data file and thus a different command.
sudo -u postgres /Library/PostgreSQL/13/bin/pg_ctl -D /Library/PostgreSQL/13/data restart
Not sure why my data dir is different than others but it worked. I also had to find my postgresql.conf file in that folder using
sudo ls -l /Library/PostgreSQL/13/data/
Upvotes: 10
Reputation: 1188
Just in case postgres has been installed using homebrew, you can also run below command:
brew services restart postgres
Upvotes: 88
Reputation: 51406
for hba.conf
changes to apply you don't need to restart - just reload.
run select pg_reload_conf()
in psql
also:
run show data_directory
in psql to find your data dir...
Upvotes: 16
Reputation: 3777
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log restart
/usr/local/var/postgres
is the location of the database storage area, and /usr/local/var/postgres/server.log
is my log file for postgres. The last word restart
is the operative word here. You can also use start
to start the service.
You can find the location of the database storage area by running ps aux | grep postgres | grep -- -D
Upvotes: 44