Sunday, May 12, 2024

Install PostgreSQL Server or Client on MacOS for testing purpose

The default PostgreSQL installation for MacOS is via installer packaged by EDB, provides more features and easier for beginners. Personally I prefer to have PostgreSQL installed in specified folders, easier to manage multiple versions co-exists on my laptop and easier to uninstall and upgrade.

  1. Download PostgreSQL binaries archive.
  1. Unzip them to a folder. Here it will unzip into /Users/donghua/Tools/pgsql
unzip postgresql-16.3-1-osx-binaries.zip -d /Users/donghua/Tools
  1. Fix com.apple.quarantine issue on MacOS

sudo xattr -dr com.apple.quarantine $i /Users/donghua/Tools/pgsql

for i in `find /Users/donghua/Tools/pgsql/bin -type f`
do
 	ls -l@ $i|grep com.apple.quarantine > /dev/null
	if [[ $? -eq 0 ]] then
		print "File quarantine: $i"
		sudo xattr -d com.apple.quarantine $i
	fi
done


for i in `find /Users/donghua/Tools/pgsql/lib -type f`
do
 	ls -l@ $i|grep com.apple.quarantine > /dev/null
	if [[ $? -eq 0 ]] then
		print "File quarantine: $i"
		sudo xattr -d com.apple.quarantine $i
	fi
done
  1. Setup your environment variables.

Here I use zsh, put below entries to ~/.zprofile


export PGHOME=/Users/donghua/Tools/pgsql
export PGDATA=/Users/donghua/Tools/pgdata/16/dataexport PATH=$PATH:$PGHOME/binalias pgadmin4="open -a '/Users/donghua/Tools/pgsql/pgAdmin 4.app'"
alias pglog='cd $PGDATA/log/;ls -1t  | head -n 1  | xargs tail -f'