Update 'Install_PostgreSQL_14_and_PostGIS_3'

Kaimbacher 2022-06-30 13:35:39 +00:00
parent 7f51e347b8
commit 819b381556

@ -12,4 +12,72 @@ sudo apt install postgresql-14-postgis-3 postgresql-14-postgis-3-scripts
```
# Step 2: Create Database
While in terminal, log in to the psql console as postgres user:
`sudo su -l postgres`
### Create users 'gn_admin' and 'gn_app' with passwords:
Create a admin user called gn_admin with new password:\
`postgres=# create user gn_admin with encrypted password 'xxx';`
> CREATE ROLE
Create an app user called gn_app with new password:\
`postgres=# create user gn_app with encrypted password 'xxx';`
> CREATE ROLE
### Create db 'gn_db' and schema 'gba':
create a database called tethys via psql:\
`postgres=# create database gn_db;`
> CREATE DATABASE
user postgres ist default owner of db gn_db
exit psql:\
`\q`
and re-login into gn_db:\
`postgres@geomon:~$psql -d gn_db -U postgres -p 5432`
create a schema 'gba' for all gn_db tabels with full authorization for the user 'gn_admin':\
`gn_db=# CREATE SCHEMA IF NOT EXISTS gba AUTHORIZATION gn_admin;`
> CREATE SCHEMA
### Change user privileges:
-> grant select, insert, update and delete privileges for the user 'gn_app':\
`gn_db=# grant usage on schema gba to gn_app;`
> GRANT
`gn_db=# grant select, insert, update, delete on all tables in schema gba to gn_app;`
> GRANT
**Default "select, insert, update, delete privileges" on tables to sos_app**\
`gn_db=# alter default privileges for role gn_admin in schema gba grant select, insert, update, delete on tables to gn_app;`
> ALTER DEFAULT PRIVILEGES
**Default usage privileges on sequences to sos_app**\
grant usage on all sequences in schema gba to sos_app:\
`gn_db=# alter default privileges for role gn_admin in schema gba grant usage on sequences to gn_app;`
> ALTER DEFAULT PRIVILEGES
**Default execute privileges on function to sos_app**\
grant execute on all functions in schema gba to sos_app:\
`alter default privileges for role gn_admin in schema gba grant execute on functions to gn_app;`
> ALTER DEFAULT PRIVILEGES
### Create extensions:
`gn_db=# CREATE EXTENSION postgis;`
> CREATE EXTENSION
`gn_db=# CREATE EXTENSION adminpack;`
> CREATE EXTENSION
`gn_db=# CREATE EXTENSION pgcrypto;`
> CREATE EXTENSION
gn_db=# SELECT postgis_full_version();
exit to administrator user:\
`\q`