今天早上,我们的生产环境只是冻结*一段时间,当更改表格时,实际上添加了一列。
令人反感的SQL:ALTER TABLE cliente ADD COLUMN topicos character varying(20)[];
*登录到我们的系统需要从同一张表中进行选择,因此在更改表期间没有人可以登录。实际上,我们必须终止进程以使系统恢复正常运行。
表结构:
CREATE TABLE cliente
(
rut character varying(30) NOT NULL,
nombre character varying(150) NOT NULL,
razon_social character varying(150) NOT NULL,
direccion character varying(200) NOT NULL,
comuna character varying(100) NOT NULL,
ciudad character varying(100) NOT NULL,
codigo_pais character varying(3) NOT NULL,
activo boolean DEFAULT true,
id serial NOT NULL,
stock boolean DEFAULT false,
vigente boolean DEFAULT true,
clase integer DEFAULT 1,
plan integer DEFAULT 1,
plantilla character varying(15) DEFAULT 'WAYPOINT'::character varying,
facturable integer DEFAULT 1,
toolkit integer DEFAULT 0,
propietario integer DEFAULT 0,
creacion timestamp without time zone DEFAULT now(),
codelco boolean NOT NULL DEFAULT false,
familia integer DEFAULT 0,
enabled_machines boolean DEFAULT false,
enabled_canbus boolean DEFAULT false,
enabled_horometro boolean DEFAULT false,
enabled_comap boolean DEFAULT false,
enabled_frio boolean DEFAULT false,
enabled_panico boolean DEFAULT false,
enabled_puerta boolean DEFAULT false,
enabled_rpm boolean DEFAULT false,
enabled_supervisor integer DEFAULT 0,
demo boolean,
interno boolean,
mqtt_enable boolean NOT NULL DEFAULT false,
topicos character varying(20)[],
CONSTRAINT pk_cliente PRIMARY KEY (rut),
CONSTRAINT fk_cliente_familiaid FOREIGN KEY (familia)
REFERENCES cliente_familia (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT pk_pais FOREIGN KEY (codigo_pais)
REFERENCES pais (codigo) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT unique_id_cliente UNIQUE (id)
)
WITH (
OIDS=FALSE
);
ALTER TABLE cliente
OWNER TO waypoint;
GRANT ALL ON TABLE cliente TO waypoint;
GRANT ALL ON TABLE cliente TO waypointtx;
GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE cliente TO waypointtomcat;
GRANT SELECT ON TABLE cliente TO waypointphp;
GRANT SELECT ON TABLE cliente TO waypointpphppublic;
GRANT ALL ON TABLE cliente TO waypointsoporte;
GRANT SELECT, INSERT ON TABLE cliente TO waypointsalesforce;
GRANT SELECT ON TABLE cliente TO waypointadminuser;
GRANT SELECT ON TABLE cliente TO waypointagenda;
GRANT SELECT ON TABLE cliente TO waypointmachines;
GRANT SELECT ON TABLE cliente TO waypointreports;
GRANT SELECT ON TABLE cliente TO readonly;
CREATE INDEX index_cliente
ON cliente
USING btree
(rut COLLATE pg_catalog."default");
CREATE INDEX index_cliente_activo
ON cliente
USING btree
(activo);
CREATE INDEX index_cliente_id_activo
ON cliente
USING btree
(id, activo);
CREATE INDEX index_cliente_rut_activo
ON cliente
USING btree
(rut COLLATE pg_catalog."default", activo);
CREATE TRIGGER trigger_default_admin
AFTER INSERT
ON cliente
FOR EACH ROW
EXECUTE PROCEDURE crea_default_admin();
CREATE TRIGGER trigger_default_grupo
AFTER INSERT
ON cliente
FOR EACH ROW
EXECUTE PROCEDURE crea_default_clientegrupo();
我应该禁用约束,触发器或其他功能吗?
也许有任何数据库优化?
我还应该提供什么进一步分析?
版本:x86_64-unknown-linux-gnu上的PostgreSQL 9.4.5,由gcc(Debian 4.9.2-10)4.9.2编译,64位