Create Database Objects¶
1. Create Database¶
- 1.1 Create Database Folder(Change
SEQASto your actual SID)
su - postgres
mkdir -p /pgdata/SEQAS_tbs/ZABBIX
chmod 700 /pgdata/SEQAS_tbs/
ll -d /pgdata/SEQAS_tbs/
- 1.2 Create tablespace(Change SID and DB)
Notiche: You must change SID and DB what you need
- 1.3 Create database and revoke public schema permission(Change
SEQASto your actual DB name)
create database "ZABBIX"
with
owner = postgres
encoding = 'UTF8'
lc_collate = 'en_US.UTF-8'
lc_ctype = 'en_US.UTF-8'
tablespace = "SEQAS_tbs"
connection limit = -1;
revoke all on schema public from public;
\l
2. Create User and schema¶
- 2.1 Create User
Users are global, and each instance can only have one account with the same name. Can Creating on all DB
- 2.2 Create Schema
\c ZABBIX
create schema "ZABBIX-IT" authorization "ZABBIX";
grant all on schema "ZABBIX-IT" to "ZABBIX";
\dn
- 2.3 Create readonly User
CREATE USER "usernamereadonly" WITH PASSWORD 'passwd';
GRANT USAGE ON SCHEMA "schemaname" TO "usernamereadonly"; ###Must exist
GRANT SELECT ON SCHEMA "schemaname" TO "usernamereadonly";
GRANT SELECT ON "schemaname".TABLENAME TO "usernamereadonly";
\du
The schema is local, and different DBs can have multiple schemas with the same name. Creating them requires switching to the corresponding DB
Notiche: Create readonly user must be chose one If the Role&Schema name are not consistent, you may need to set search_path Example: Database Level: DB=# ALTER ROLE Username IN DATABASE "Databasename" SET search_path TO "schemaname, public";
Cluster Level: DB=# ALTER ROLE Username SET search_path TO "schemaname, public";




