Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save timurguseynov/8e8b906bff849c8cd2cc8f805a9de564 to your computer and use it in GitHub Desktop.
Save timurguseynov/8e8b906bff849c8cd2cc8f805a9de564 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment