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
- Host: GitHub
- URL: https://github.com/viktorvx/postgresql-create-db-sample
- Owner: ViktorVx
- Created: 2022-02-21T15:03:07.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-07-13T15:56:23.000Z (almost 3 years ago)
- Last Synced: 2025-01-26T09:42:56.174Z (5 months ago)
- Topics: create-database, create-user, grants, postgresql
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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 ;
```