setup/doc/postgres.md

85 lines
2.3 KiB
Markdown
Raw Normal View History

2022-04-14 10:21:05 +02:00
# Setup Postgres
2022-06-05 08:35:59 +02:00
* install Postgres like [this](./postgres-install.md)
2022-04-14 10:21:05 +02:00
2022-05-25 13:25:51 +02:00
* create copy of config file ```pg_hba.conf file```\
NOTE: Insert the postgresql version <psql version> that is running on the respective host
2022-04-14 10:21:05 +02:00
```
2022-05-25 13:25:51 +02:00
cd /etc/postgresql/<psql version>/main/
sudo cp pg_hba.conf pg_hba.conf-backup
2022-04-14 10:21:05 +02:00
```
2022-05-25 13:25:51 +02:00
* switch authentication method from ```peer``` to ```md5``` for all local users connecting by Unix domain sockets by opening the following config file and adding the example configuration
2022-04-14 10:21:05 +02:00
```
2022-05-25 13:25:51 +02:00
sudo vi pg_hba.conf
2022-04-14 10:21:05 +02:00
```
```
# "local" is for Unix domain socket connections only
2022-05-25 13:25:51 +02:00
#local all all peer
local all all md5
2022-04-14 10:21:05 +02:00
```
* restart PostgreSQL to enable the changes
```
2022-05-25 13:25:51 +02:00
systemctl status postgresql
2022-04-14 10:21:05 +02:00
sudo systemctl restart postgresql
systemctl status postgresql
```
2022-05-25 13:25:51 +02:00
TODO: move the following description to dedicated setup files
# Allow Remote Connections
2022-04-14 10:21:05 +02:00
* configure ports and update firewall using the [firewall setup](firewall.md)
```
sudo ufw allow 5432
sudo ufw enable
sudo ufw status numbered
```
* create config backup
```
2022-04-22 15:43:30 +02:00
sudo cp /etc/postgresql/<version>/main/postgresql.conf /etc/postgresql/<version>/main/postgresql.conf-backup
2022-04-14 10:21:05 +02:00
```
2022-04-28 14:05:52 +02:00
* open config file to define what IP addresses postgres to listen on
2022-04-14 10:21:05 +02:00
```
2022-04-22 15:43:30 +02:00
sudo vi /etc/postgresql/<version>/main/postgresql.conf
2022-04-14 10:21:05 +02:00
```
* edit config file like this
```
#listen_addresses = 'localhost'
listen_addresses = '*'
```
2022-04-28 14:05:52 +02:00
* open config file to define access to all databases for all users with an encrypted key
2022-04-14 10:21:05 +02:00
```
2022-04-22 15:43:30 +02:00
sudo vi /etc/postgresql/<version>/main/pg_hba.conf
2022-04-14 10:21:05 +02:00
```
* edit config file like this
```
# TYPE DATABASE USER ADDRESS METHOD
host all all 0.0.0.0/0 md5
host all all :/0 md5
```
* restart PostgreSQL to enable the changes
```
sudo systemctl restart postgresql
systemctl status postgresql
```
# Disable Start Up At System Boot
* If you install the PostgreSQL database from packages, it is automatically added to the start up scripts of the operating system. If you are only learning to work with the database, it is unnecessary to start the database each time you boot the system. Remove system startup link for the PostgreSQL database
```
sudo update-rc.d -f postgresql remove
```
# Links
* [PostgreSQL Java](https://zetcode.com/java/postgresql/)