postgresql基础

03 Mar 2016, by

初始化postgresql

备份与恢复

mac安装postgres

基本命令

基本数据操作

SELECT 
    pg_terminate_backend(pid) 
FROM 
    pg_stat_activity 
WHERE 
    -- don't kill my own connection!
    pid <> pg_backend_pid()
    -- don't kill the connections to other databases
    AND datname = 'database_name'
    ;
REVOKE CONNECT ON DATABASE dbname FROM PUBLIC, username;

dropdb -U postgres db_name
SELECT *
  FROM information_schema.columns
 WHERE table_schema = 'public'
   AND table_name   = 'your_table'
     ; 

导入数据时,新旧表不一样(null value in column “contract_code_md5” of relation “smart_contracts” violates not-null constraint)

ALTER TABLE my_table ALTER COLUMN xtra_col SET DEFAULT 'b';
COPY my_table (col1, col2, col3) FROM '/workdir/some_file.txt' WITH (FORMAT CSV, DELIMITER '|', NULL 'NULL', HEADER true);
ALTER TABLE my_table ALTER COLUMN xtra_col DROP DEFAULT;