Setup postgres in Ubuntu server
To install PostgreSQL in Ubuntu (tested in 20.04)
1 | echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list |
The version installed here is v13
First time setup
For the first time, we need to create a new user & a new database
Switch to postgres user
1 | root@host:/root# su postgres |
Then
1 | postgres=# CREATE ROLE my_user LOGIN PASSWORD 'secret'; |
Import data if necessary
Then run
1 | postgres=# \c my_database |
Then back to root user. To enable public remote access
1 | postgres@host:/root$ exit |
Change listen_addresses value to *
1 | listen_addresses = '*' |
Then edit pg_hba.conf
1 | root@host:/root# vim /etc/postgresql/13/main/pg_hba.conf |
Change the line
1 | host all all 127.0.0.1/32 md5 |
to
1 | host all all 0.0.0.0/0 md5 |
Then restart server
1 | root@host:/root# service postgresql restart |