Last active
July 1, 2025 02:22
-
-
Save DrTom/4f2edcac26a0eae82360dbc9b18dd82c to your computer and use it in GitHub Desktop.
Revisions
-
DrTom revised this gist
Jul 26, 2024 . 1 changed file with 54 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,7 @@ # PostgreSQL Server Setup on Mac OS with MacPorts This is in particular aimed at using multiple versions of PostgreSQL at different ports. export VERSION=15 ## Install @@ -40,4 +42,56 @@ initially also as user `postgres` ``` CREATE USER tom WITH SUPERUSER LOGIN PASSWORD 'tom'; CREATE DATABASE tom owner tom ``` ## My `bash` Config ``` # POSTGRESQL ################################################################## function pg_env_set(){ if [ -z $1 ]; then export PGVERSION=$1 else export PGVERSION=${1:-"15"} fi if shopt -q login_shell; then save_echo "SETTING UP POSTGRES ENVIRONMENT FOR VERSION ${PGVERSION}" fi export POSTGRESQL="/opt/local/lib/postgresql${PGVERSION}" case $PGVERSION in *) export PGPORT="54${PGVERSION}" ;; esac export PATH="$POSTGRESQL/bin:$PATH" export PGUSER="tom" export PGPASSWORD="tom" export PGPIDNAME="pid" } function pg_start(){ sudo -i -u postgres /opt/local/lib/postgresql${PGVERSION}/bin/pg_ctl \ -D /opt/local/var/db/postgresql${PGVERSION}/defaultdb \ -l /opt/local/var/log/postgresql${PGVERSION}/postgres.log \ start } function pg_stop(){ set -euo pipefail sudo -u postgres /opt/local/lib/postgresql${PGVERSION}/bin/pg_ctl \ -D /opt/local/var/db/postgresql${PGVERSION}/defaultdb \ stop } pg_env_set 15 # END POSTGRESQL ############################################################## ``` -
DrTom revised this gist
Jul 26, 2024 . 1 changed file with 1 addition and 31 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,22 +21,8 @@ sudo su postgres -c 'cd /opt/local/var/db/postgresql${VERSION} && /opt/local/lib change the `port` in `/opt/local/var/db/postgresql${VERSION}/defaultdb/postgresql.conf` our|my convention is to use "54${VERSION}", currently 5415 ## Starting manually / Troubleshooting @@ -46,22 +32,6 @@ 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 ``` ## Add User -
DrTom revised this gist
Oct 21, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ ``` port info postgresql${VERSION}-server port install postgresql${VERSION}-server ``` ## Initial Setup -
DrTom revised this gist
Mar 8, 2023 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -68,6 +68,6 @@ sudo -u postgres /opt/local/lib/postgresql10/bin/pg_ctl -D /opt/local/var/db/pos initially also as user `postgres` ``` CREATE USER tom WITH SUPERUSER LOGIN PASSWORD 'tom'; CREATE DATABASE tom owner tom ``` -
DrTom revised this gist
Mar 8, 2023 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,6 +19,8 @@ sudo su postgres -c 'cd /opt/local/var/db/postgresql${VERSION} && /opt/local/lib ``` change the `port` in `/opt/local/var/db/postgresql${VERSION}/defaultdb/postgresql.conf` ### ## Load and Unload -
DrTom revised this gist
Mar 8, 2023 . 1 changed file with 10 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,22 +1,26 @@ # PostgreSQL Server Setup on Mac OS with MacPorts export VERSION=15 ## Install ``` port info postgresql${VERSION}-server port install postgresq${VERSION}-server ``` ## Initial Setup ```sh 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' ``` ### ## Load and Unload **This seems to be broken** => manual start, see below @@ -37,7 +41,7 @@ see also https://guide.macports.org/chunked/reference.startupitems.html#referenc 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: -
DrTom revised this gist
Oct 23, 2021 . 1 changed file with 7 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # PostgreSQL Server Setup on Mac OS with MacPorts ## Install @@ -51,6 +51,12 @@ sudo -u postgres /opt/local/lib/postgresql10/bin/pg_ctl -D /opt/local/var/db/pos /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` -
DrTom revised this gist
Aug 26, 2021 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -42,6 +42,11 @@ as user `postgres`, e.g. `sudo -i -u postgres` 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 ``` -
DrTom revised this gist
Aug 24, 2020 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -40,6 +40,12 @@ as user `postgres`, e.g. `sudo -i -u postgres` /opt/local/lib/postgresql12/bin/pg_ctl -D /opt/local/var/db/postgresql12/defaultdb start -l /opt/local/var/log/postgresql12/postgres.log ``` for version 10 pg server: ``` /opt/local/lib/postgresql10/bin/pg_ctl -D /opt/local/var/db/postgresql10/defaultdb start -l /opt/local/var/log/postgresql10/postgres.log ``` ## Add User initially also as user `postgres` -
DrTom revised this gist
Jun 24, 2020 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ # PostgreSQL 12 Server Setup on Mac OS with MacPorts ## Install ``` -
DrTom revised this gist
Jun 24, 2020 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -40,6 +40,8 @@ as user `postgres`, e.g. `sudo -i -u postgres` ## Add User initially also as user `postgres` ``` CREATE USER thomas WITH SUPERUSER LOGIN PASSWORD 'thomas'; CREATE DATABASE thomas owner thomas -
DrTom revised this gist
Jun 24, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,7 +17,7 @@ sudo su postgres -c 'cd /opt/local/var/db/postgresql12 && /opt/local/lib/postgre ## Load and Unload **This seems to be broken** => manual start, see below ``` port unload postgresql12-server -
DrTom revised this gist
Jun 24, 2020 . 1 changed file with 9 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,6 +17,8 @@ sudo su postgres -c 'cd /opt/local/var/db/postgresql12 && /opt/local/lib/postgre ## Load and Unload ** This seems to be broken** => manual start, see below ``` port unload postgresql12-server port load postgresql12-server @@ -34,4 +36,11 @@ as user `postgres`, e.g. `sudo -i -u postgres` ``` /opt/local/lib/postgresql12/bin/pg_ctl -D /opt/local/var/db/postgresql12/defaultdb start -l /opt/local/var/log/postgresql12/postgres.log ``` ## Add User ``` CREATE USER thomas WITH SUPERUSER LOGIN PASSWORD 'thomas'; CREATE DATABASE thomas owner thomas ``` -
DrTom revised this gist
Jun 24, 2020 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,6 +30,8 @@ see also https://guide.macports.org/chunked/reference.startupitems.html#referenc ## Starting manually / Troubleshooting as user `postgres`, e.g. `sudo -i -u postgres` ``` /opt/local/lib/postgresql12/bin/pg_ctl -D /opt/local/var/db/postgresql12/defaultdb start -l /opt/local/var/log/postgresql12/postgres.log ``` -
DrTom revised this gist
Jun 22, 2020 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,9 +28,8 @@ see also https://guide.macports.org/chunked/reference.startupitems.html#referenc `/opt/local/etc/LaunchDaemons/org.macports.postgresql12-server/postgresql12-server.wrapper` ## Starting manually / Troubleshooting ``` /opt/local/lib/postgresql12/bin/pg_ctl -D /opt/local/var/db/postgresql12/defaultdb start -l /opt/local/var/log/postgresql12/postgres.log ``` -
DrTom revised this gist
Jun 22, 2020 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,9 +8,11 @@ port install postgresql12-server ## Initial Setup ```sh sudo mkdir -p /opt/local/var/db/postgresql12/defaultdb sudo chown postgres:postgres /opt/local/var/db/postgresql12/defaultdb sudo su postgres -c 'cd /opt/local/var/db/postgresql12 && /opt/local/lib/postgresql12/bin/initdb -D /opt/local/var/db/postgresql12/defaultdb' ``` ## Load and Unload -
DrTom revised this gist
Jun 22, 2020 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,6 +24,8 @@ see also https://guide.macports.org/chunked/reference.startupitems.html#referenc `/Library/LaunchDaemons/org.macports.postgresql12-server.plist` `/opt/local/etc/LaunchDaemons/org.macports.postgresql12-server/postgresql12-server.wrapper` ## Troubleshooting ``` -
DrTom revised this gist
Jun 22, 2020 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,7 +20,9 @@ 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` ## Troubleshooting -
DrTom revised this gist
Jun 22, 2020 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,6 +20,8 @@ port unload postgresql12-server port load postgresql12-server ``` see also https://guide.macports.org/chunked/reference.startupitems.html#reference.startupitems.internals ## Troubleshooting ``` -
DrTom revised this gist
Jun 22, 2020 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,5 +23,6 @@ port load postgresql12-server ## Troubleshooting ``` /opt/local/lib/postgresql12/bin/pg_ctl -D /opt/local/var/db/postgresql12/defaultdb -l logfile start ``` -
DrTom revised this gist
Jun 22, 2020 . 1 changed file with 6 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,6 @@ port info postgresql12-server port install postgresql12-server ``` ## Initial Setup ```sh @@ -19,4 +18,10 @@ sudo su postgres -c '/opt/local/lib/postgresql12/bin/initdb -D /opt/local/var/db ``` port unload postgresql12-server port load postgresql12-server ``` ## Troubleshooting ``` pg_ctl -D /opt/local/var/db/postgresql12/defaultdb/ start ``` -
DrTom revised this gist
Jun 22, 2020 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,11 @@ ## Install ``` port info postgresql12-server port install postgresql12-server ``` ## Initial Setup ```sh -
DrTom revised this gist
Jun 22, 2020 . 1 changed file with 9 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,14 @@ ## Initial Setup ```sh sudo mkdir -p /opt/local/var/db/postgresql12/defaultdb sudo chown postgres:postgres /opt/local/var/db/postgresql12/defaultdb sudo su postgres -c '/opt/local/lib/postgresql12/bin/initdb -D /opt/local/var/db/postgresql12/defaultdb' ``` ## Load and Unload ``` port unload postgresql12-server port load postgresql12-server ``` -
DrTom created this gist
Jun 22, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ ```sh sudo mkdir -p /opt/local/var/db/postgresql12/defaultdb sudo chown postgres:postgres /opt/local/var/db/postgresql12/defaultdb sudo su postgres -c '/opt/local/lib/postgresql12/bin/initdb -D /opt/local/var/db/postgresql12/defaultdb' ```