An open API service indexing awesome lists of open source software.

https://github.com/viktorvx/postgresql-create-db-sample

Example how to create postgresql db with users and grants
https://github.com/viktorvx/postgresql-create-db-sample

create-database create-user grants postgresql

Last synced: 3 months ago
JSON representation

Example how to create postgresql db with users and grants

Awesome Lists containing this project

README

        

## Sample how to create postgresql database

### Create folders for tablespace

```shell script
mkdir -p /pgdata/pg_tblspc/_ts_idx
mkdir -p /pgdata/pg_tblspc/_ts_data
chown -R postgres:postgres /pgdata/pg_tblspc/_ts_idx
chown -R postgres:postgres /pgdata/pg_tblspc/_ts_data
chmod 700 /pgdata/pg_tblspc/_ts_idx
chmod 700 /pgdata/pg_tblspc/_ts_data
```

### Create database objects

```sql
--- Create database
create database ;

--- Create users, schemas, tablespace
create user with encrypted password 'password';
create schema ;
create schema ext;
grant connect on database to ;
grant all on schema to ;
alter user VALID UNTIL 'infinity';
grant usage on schema to ;
alter default privileges in schema grant ALL on tables to ;
grant select on all sequences in schema to ;
grant all privileges on all tables in schema to ;
grant select on all tables in schema to ;

--- Create tablespace
create tablespace _ts_data owner location '/pgdata/pg_tblspc/_ts_data';
create tablespace _ts_idx owner location '/pgdata/pg_tblspc/_ts_idx';

--- Grant permissions
grant usage on schema ext to ;

--- Create extensions
create extension "uuid-ossp" schema ext;
create extension pgcrypto schema ext;
create extension pg_cron schema ext;
```
if files for tablespaces were already created you need this also:
```sql
grant all on tablespace to ;
```