In your command-line run the following commands:
brew doctorbrew update
-
In your command-line run the command:
brew install postgres -
Configuration can be found in this file:
/usr/local/opt/postgresql/homebrew.mxcl.postgresql.plist -
Create new aliases to start and stop postgres server (in .bachrc/.zshrc/etc.):
alias pg_start="brew services start postgresql" alias pg_stop="brew services stop postgresql" -
Run the aliases:
-
to start database service
$ pg_start -
to check if database service running or not:
$ brew services listOR
$ ps aux | grep postgres -
to stop database service.
$ pg_stop
-
Connect to database
postgreswithpsql$ psql postgres psql (14.1) Type "help" for help. postgres=# -
createuser -s postgres- fixesrole "postgres" does not exist -
Create database:
createdb `whoami`
- Change data directory (DATADIR):
-
In the file "/usr/local/opt/postgresql/homebrew.mxcl.postgresql.plist"
-
Change the default location, value after option -D, to a custom directory, e.g. "/Users/abc/postgres":
<key>ProgramArguments</key> <array> <string>/usr/local/opt/postgresql/bin/postgres</string> <string>-D</string> <string>/Users/abc/postgres</string> </array> -
Directoy "/Users/abc/postgres" must have either permission
u=rwx (0700)oru=rwx,g=rx (0750):$ chmod 0750 /Users/abc/postgres
-
Change log file directory:
<key>StandardErrorPath</key> <string>/usr/local/var/log/postgres.log</string> <key>StandardOutPath</key> <string>/usr/local/var/log/postgres.log</string>