{"id":21834525,"url":"https://github.com/viktorvx/postgresql-create-db-sample","last_synced_at":"2025-03-21T14:18:45.034Z","repository":{"id":138976838,"uuid":"461910418","full_name":"ViktorVx/postgresql-create-db-sample","owner":"ViktorVx","description":"Example how to create postgresql db with users and grants","archived":false,"fork":false,"pushed_at":"2022-07-13T15:56:23.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-26T09:42:56.174Z","etag":null,"topics":["create-database","create-user","grants","postgresql"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ViktorVx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-21T15:03:07.000Z","updated_at":"2023-07-28T21:29:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"7f3cba5b-95ce-4490-a581-ffed8193eee8","html_url":"https://github.com/ViktorVx/postgresql-create-db-sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ViktorVx%2Fpostgresql-create-db-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ViktorVx%2Fpostgresql-create-db-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ViktorVx%2Fpostgresql-create-db-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ViktorVx%2Fpostgresql-create-db-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ViktorVx","download_url":"https://codeload.github.com/ViktorVx/postgresql-create-db-sample/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244811375,"owners_count":20514276,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["create-database","create-user","grants","postgresql"],"created_at":"2024-11-27T20:11:47.310Z","updated_at":"2025-03-21T14:18:45.008Z","avatar_url":"https://github.com/ViktorVx.png","language":null,"readme":"## Sample how to create postgresql database\n\n### Create folders for tablespace\n\n```shell script\nmkdir -p /pgdata/pg_tblspc/\u003cname\u003e_ts_idx\nmkdir -p /pgdata/pg_tblspc/\u003cname\u003e_ts_data\nchown -R postgres:postgres /pgdata/pg_tblspc/\u003cname\u003e_ts_idx\nchown -R postgres:postgres /pgdata/pg_tblspc/\u003cname\u003e_ts_data\nchmod 700 /pgdata/pg_tblspc/\u003cname\u003e_ts_idx\nchmod 700 /pgdata/pg_tblspc/\u003cname\u003e_ts_data\n``` \n\n### Create database objects\n\n```sql\n--- Create database\ncreate database \u003cdatabase_name\u003e;\n \n--- Create users, schemas, tablespace\ncreate user \u003cuser_name\u003e with encrypted password 'password';\ncreate schema \u003cschema_name\u003e;\ncreate schema ext;\ngrant connect on database \u003cdb_name\u003e to \u003cuser_name\u003e;\ngrant all on schema \u003cschema_name\u003e to \u003cuser_name\u003e;\nalter user \u003cuser_name\u003e VALID UNTIL 'infinity';\ngrant usage on schema \u003cschema_name\u003e to \u003cuser_name\u003e;\nalter default privileges in schema \u003cschema_name\u003e grant ALL on tables to \u003cuser_name\u003e;\ngrant select on all sequences in schema \u003cschema_name\u003e to \u003cuser_name\u003e;\ngrant all privileges on all tables in schema \u003cschema_name\u003e to \u003cuser_name\u003e;\ngrant select on all tables in schema \u003cschema_name\u003e to \u003cuser_name\u003e;\n\n--- Create tablespace\ncreate tablespace \u003cname\u003e_ts_data owner \u003cschema_name\u003e location '/pgdata/pg_tblspc/\u003cname\u003e_ts_data';\ncreate tablespace \u003cname\u003e_ts_idx owner \u003cschema_name\u003e location '/pgdata/pg_tblspc/\u003cname\u003e_ts_idx';\n\n--- Grant permissions\ngrant usage on schema ext to \u003cuser_name\u003e;\n\n--- Create extensions\ncreate extension \"uuid-ossp\" schema ext;\ncreate extension pgcrypto schema ext;\ncreate extension pg_cron schema ext; \n```\nif files for tablespaces were already created you need this also:\n```sql\ngrant all on tablespace \u003ctablespace_name\u003e to \u003cuser_name\u003e;\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fviktorvx%2Fpostgresql-create-db-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fviktorvx%2Fpostgresql-create-db-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fviktorvx%2Fpostgresql-create-db-sample/lists"}