https://github.com/thesurlydev/postgresql-setup
Instructions for setting up a new PostgreSQL database on Ubuntu
https://github.com/thesurlydev/postgresql-setup
Last synced: 5 months ago
JSON representation
Instructions for setting up a new PostgreSQL database on Ubuntu
- Host: GitHub
- URL: https://github.com/thesurlydev/postgresql-setup
- Owner: thesurlydev
- Created: 2022-06-12T17:24:30.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-06-12T19:52:44.000Z (almost 4 years ago)
- Last Synced: 2025-02-06T18:52:26.527Z (over 1 year ago)
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# postgresql setup
The following are instructions for setting up a new PostgreSQL database on Ubuntu. These instructions assume that the db host does not have a public route so be careful!
## install
```shell
# Update the package lists:
sudo apt-get update
```
```
# Install the latest version of PostgreSQL.
# If you want a specific version, use 'postgresql-12' or similar instead of 'postgresql':
sudo apt install postgresql postgresql-contrib -y
```
NOTE: To install a newer vesrion (>12), following instructions here: https://wiki.postgresql.org/wiki/Apt
## create role
```
sudo -u postgres psql
createuser --interactive
```
output:
```
Enter name of role to add: shane
Shall the new role be a superuser? (y/n) y
```
An assumption that the Postgres authentication system makes by default is that for any role used to log in, that role will have a database with the same name which it can access.
```
sudo -u postgres createdb shane
```
### set a password
```
sudo -u user_name psql db_name
ALTER USER user_name WITH PASSWORD 'new_password';
```
## config
Two changes are necessary in order to allow connections to databases aside from localhost.
First, update `/etc/postgresql/12/main/postgresql.conf` and replace the line:
```
listen_addresses = 'localhost'
```
with
```
listen_addresses = '*'
```
Second, update `/etc/postgresql/12/main/pg_hba.conf` and add the following lines:
```
host all all 0.0.0.0/0 md5
host all all ::/0 md5
```
Now, restart postgresql server:
```
sudo service postgresql restart
```
## references
* https://www.digitalocean.com/community/tutorials/how-to-install-postgresql-on-ubuntu-20-04-quickstart
* https://www.bigbinary.com/blog/configure-postgresql-to-allow-remote-connection
* https://wiki.postgresql.org/wiki/Apt