Skip to content

Instantly share code, notes, and snippets.

@jaime-ez
Last active January 27, 2020 21:17
Show Gist options
  • Save jaime-ez/c7ede87969f1884710545a01371ac3d4 to your computer and use it in GitHub Desktop.
Save jaime-ez/c7ede87969f1884710545a01371ac3d4 to your computer and use it in GitHub Desktop.
Setup postgresql on Linux

Setting up Postgresql on a new Debian8 instance

Install necessary packages

# run as root
root$ apt-get update && apt-get upgrade
root$ echo "deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main" >> /etc/apt/sources.list
root$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
root$ apt-get update -y
root$ apt-get install postgresql-9.5 -y

Add a non-root user

# you don't want to stay logged in as root
root$ adduser testUser  
root$ usermod -aG sudo testUser  

Do the rest of this guide while logged in as your new user.

Postgresql setup

In order to use postgresql, you'll need a user/password on postgres, as well as a database. First, use su to become the postgres user, and make a user on postgres with your username:

$ sudo su - postgres
postgres$ createuser testUser

psql launches the postgres prompt, which you'll use in order to set your password. \q quits the postgres prompt, returning you to the bash command line.

postgres$ psql
postgres=> ALTER USER "testUser" WITH PASSWORD 'PASSWORD';
# outputs: ALTER ROLE
postgres=> \q

Finally, create the database while logged in as the postgres user.

postgres$ createdb testDb
postgres$ exit

Then you can login to the database with

$ psql testDb

Manage postgres server

sudo systemctl disable postgresql sudo systemctl enable postgresql sudo service postgresql restart

Credits

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-14-04
https://github.com/interledgerjs/ilp-kit/blob/master/docs/SETUP.md#get-a-server-instance

@jaime-ez
Copy link
Author

Importing a dump from google cloud:

create table, create user, check that pg_hba.conf has the auth method for user set as md5, run command psql -U user db_name < sql_dump

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