我绝对是 postgres 的新手。我使用的是 9.2 版。我正在尝试编写一个脚本来创建一些角色、一个数据库、一个模式和一个基本表。我尝试在 pgAdminIII 中使用 sql 编辑器,但一直遇到这样的错误:
ERROR: CREATE DATABASE cannot be executed from a function or multi-command string
我从其他帖子中了解到,这根本不是如何在 postgres 中执行此操作,但我还没有弄清楚有人如何将他们的 ddl 组织在一个文件中以构建数据库、模式、角色、表等的集合.
这是我目前正在尝试创建的基本数据库布局的示例:
CREATE ROLE "edus-db-admins-dev"
NOSUPERUSER INHERIT CREATEROLE;
CREATE ROLE "edus-db-admin-dev" LOGIN
PASSWORD 'blahblahblah'
NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;
GRANT "edus-db-admins-dev" TO "edus-db-admin-dev";
CREATE ROLE "edus-esb-loggers"
NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;
CREATE ROLE "edus-esb-logger" LOGIN
PASSWORD 'blahblahblah'
NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;
CREATE DATABASE edus
WITH OWNER = "edus-db-admin-dev"
ENCODING = 'UTF8'
TABLESPACE = pg_default
LC_COLLATE = 'English_United States.1252'
LC_CTYPE = 'English_United States.1252'
CONNECTION LIMIT = -1;
CREATE SCHEMA eduspubservice
AUTHORIZATION "edus-db-admin-dev";
CREATE TABLE eduspubservice.logs
(
date date NOT NULL,
level character varying(10),
category character varying(100),
logger character varying(100),
method character varying(100),
message character varying(10000)
)
WITH (
OIDS=FALSE
);
ALTER TABLE eduspubservice.logs
OWNER TO "edus-esb-logger";