Skip to content

Instantly share code, notes, and snippets.

@DrTom
Last active December 28, 2023 09:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save DrTom/4f2edcac26a0eae82360dbc9b18dd82c to your computer and use it in GitHub Desktop.
Save DrTom/4f2edcac26a0eae82360dbc9b18dd82c to your computer and use it in GitHub Desktop.
MacPort PostgreSQL setup

PostgreSQL Server Setup on Mac OS with MacPorts

export VERSION=15

Install

port info postgresql${VERSION}-server
port install postgresql${VERSION}-server

Initial Setup

sudo mkdir -p /opt/local/var/db/postgresql${VERSION}/defaultdb
sudo chown postgres:postgres /opt/local/var/db/postgresql${VERSION}/defaultdb
sudo su postgres -c 'cd /opt/local/var/db/postgresql${VERSION} && /opt/local/lib/postgresql15/bin/initdb -D /opt/local/var/db/postgresql15/defaultdb'

change the port in /opt/local/var/db/postgresql${VERSION}/defaultdb/postgresql.conf

Load and Unload

This seems to be broken => manual start, see below

port unload postgresql12-server
port load postgresql12-server

see also https://guide.macports.org/chunked/reference.startupitems.html#reference.startupitems.

/Library/LaunchDaemons/org.macports.postgresql12-server.plist

/opt/local/etc/LaunchDaemons/org.macports.postgresql12-server/postgresql12-server.wrapper

Starting manually / Troubleshooting

as user postgres, e.g. sudo -i -u postgres

/opt/local/lib/postgresql${VERSION}/bin/pg_ctl -D /opt/local/var/db/postgresql${VERSION}/defaultdb start -l /opt/local/var/log/postgresql${VERSION}/postgres.log

for version 10 pg server:

oneliner:

sudo -u postgres /opt/local/lib/postgresql10/bin/pg_ctl -D /opt/local/var/db/postgresql10/defaultdb start -l /opt/local/var/log/postgresql10/postgres.log
/opt/local/lib/postgresql10/bin/pg_ctl -D /opt/local/var/db/postgresql10/defaultdb start -l /opt/local/var/log/postgresql10/postgres.log

pg 13

/opt/local/lib/postgresql13/bin/pg_ctl -D /opt/local/var/db/postgresql13/defaultdb -l /opt/local/var/log/postgresql13/postgres.log start

Add User

initially also as user postgres

CREATE USER tom WITH SUPERUSER LOGIN PASSWORD 'tom';
CREATE DATABASE tom owner tom
@syam-nd
Copy link

syam-nd commented Oct 21, 2023

@DrTom Thanks for taking time to document this. I would like to point out a typo in 'Install' section. You missed out on 'l' in 'port install postgresq${VERSION}-server'

@DrTom
Copy link
Author

DrTom commented Oct 21, 2023

@DrTom Thanks for taking time to document this. I would like to point out a typo in 'Install' section. You missed out on 'l' in 'port install postgresq${VERSION}-server'

fixed, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment