Skip to content

Instantly share code, notes, and snippets.

@coreymcmahon
Last active December 28, 2022 15:51
Show Gist options
  • Save coreymcmahon/1033ec6ad5868bdff6e4026d2e909370 to your computer and use it in GitHub Desktop.
Save coreymcmahon/1033ec6ad5868bdff6e4026d2e909370 to your computer and use it in GitHub Desktop.
Postgres 14 installation on Ubuntu 20+
# Install Postgres 14
sudo apt-get update
sudo apt-get -y upgrade
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/postgresql-pgdg.list > /dev/null
# Might need to do this if you get "...public key is not available: NO_PUBKEY 7FCC7D46ACCC4CF8"
# sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys <MISSING PUBKEY>
sudo apt-get update
sudo apt-get install -y postgresql-14
# Create the database and user
sudo su - postgres
psql -U postgres -c "CREATE DATABASE databasename;";
psql -U postgres -c "CREATE ROLE databaseuser WITH LOGIN PASSWORD 'secretpassword';" databasename;
psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE databasename TO databaseuser;";
# Update listen_addresses...
vi /etc/postgresql/14/main/postgresql.conf
# Add remote host(s)...
vi /etc/postgresql/14/main/pg_hba.conf
# Restart Postgres
exit # Stop su
sudo systemctl restart postgresql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment