安装
sh-4.2# yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm sh-4.2# yum install postgresql11 sh-4.2# yum install postgresql11-server
初始化
sh-4.2# /usr/pgsql-11/bin/postgresql-11-setup initdb
启动
sh-4.2# systemctl enable postgresql-11 sh-4.2# systemctl start postgresql-11 sh-4.2# su - postgres sh-4.2# psql -U postgres
常用命令
# 创建新表 postgres=# CREATE TABLE user_tbl(name VARCHAR(20), signup_date DATE); # 插入数据 postgres=# INSERT INTO user_tbl(name, signup_date) VALUES('张三', '2013-12-22'); # 选择记录 postgres=# SELECT * FROM user_tbl; # 更新数据 postgres=# UPDATE user_tbl set name = '李四' WHERE name = '张三'; # 删除记录 postgres=# DELETE FROM user_tbl WHERE name = '李四' ; # 添加栏位 postgres=# ALTER TABLE user_tbl ADD email VARCHAR(40); # 更新结构 postgres=# ALTER TABLE user_tbl ALTER COLUMN signup_date SET NOT NULL; # 更名栏位 postgres=# ALTER TABLE user_tbl RENAME COLUMN signup_date TO signup; # 删除栏位 postgres=# ALTER TABLE user_tbl DROP COLUMN email; # 表格更名 postgres=# ALTER TABLE user_tbl RENAME TO backup_tbl; # 删除表格 postgres=# DROP TABLE IF EXISTS backup_tbl;
参考地址
https://www.postgresql.org/download/linux/redhat/
https://www.jianshu.com/p/8515a02492f1