62

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

8 Answers 8

93

Just in case postgres has been installed using homebrew, you can also run below command:

brew services restart postgres
Sign up to request clarification or add additional context in comments.

4 Comments

Error: Formula postgresql is not installed.
Use brew services list to get the right service name. Then use brew services restart <service name>. Example brew services restart postgresql@12
For me it was, 'brew services restart postgresql@14'. Use the package name when you installed it using brew.
This gave a 'Error: No available formula with the name "postgres"' for me. Changing it to brew services restart postgresql was successful though.
44
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

7 Comments

pg_ctl: directory "/usr/local/var/postgres" does not exist
Updated my post
Ah I just saw your edit. Try this: pg_ctl -D /Users/TheKotik/Library/Application Support/Postgres/var-9.6 -l /Users/TheKotik/Library/Application Support/Postgres/var-9.6/server.log restart
Surround the arguments in quotes: pg_ctl -D "/Users/TheKotik/Library/Application Support/Postgres/var-9.6" -l "/Users/TheKotik/Library/Application Support/Postgres/var-9.6/server.log" restart
pg_ctl: could not open PID file "/Library/PostgreSQL/9.6/data/postmaster.pid": Permission denied
|
16

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...

5 Comments

select pg_reload_conf() has no effect
then you probably edit wrong hba file... in posql run show hba_file to check
thanks a lot..I was restarting machine after adding entry in pg_hba.conf...saved lots of time...thanks a lot.
sure thing. my pleasure
select pg_reload_conf() might have no effect because you need to add a ; after it to run the command.
13

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/

Comments

7

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

Comments

3

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

Comments

2

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

Comments

2

For mac

sudo -u postgres /Library/PostgreSQL/15/bin/pg_ctl -D /Library/PostgreSQL/15/data restart

Worked for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.