扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
这篇文章主要介绍PostgreSQL常用命令有哪些,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
创新互联专业为企业提供慈利网站建设、慈利做网站、慈利网站设计、慈利网站制作等企业网站建设、网页设计与制作、慈利企业网站模板建站服务,10余年慈利做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
mydb=# SELECT version(); version ------------------------------------------------------------------------------------------------------- PostgreSQL 9.3.6 on i686-pc-linux-gnu, compiled by gcc (GCC) 4.4.6 20110731 (Red Hat 4.4.6-3), 32-bit (1 row)
mydb=# CREATE DATABASE test; CREATE DATABASE
mydb-# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+---------+----------+-------------+-------------+--------------------- mydb | postgre | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | postgres | postgre | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | template0 | postgre | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgre + | | | | | postgre=CTc/postgre template1 | postgre | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgre + | | | | | postgre=CTc/postgre test | postgre | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | (5 rows)
mydb-# \c test Password for user postgre: You are now connected to database "test" as user "postgre".
# 不能删除当前连接的数据库 test=# DROP DATABASE test; ERROR: cannot drop the currently open database test=# DROP DATABASE mydb; DROP DATABASE
test=# create table t as select * from pg_tablespace; SELECT 2 test=# \dt List of relations Schema | Name | Type | Owner --------+------+-------+--------- public | t | table | postgre (1 row)
test=# \d t Table "public.t" Column | Type | Modifiers ------------+-----------+----------- spcname | name | spcowner | oid | spcacl | aclitem[] | spcoptions | text[] |
test=# alter table t rename to t_t; ALTER TABLE test=# \dt List of relations Schema | Name | Type | Owner --------+------+-------+--------- public | t_t | table | postgre (1 row)
# 创建索引 test=# create index idx_name on t (spcname); CREATE INDEX # 显示索引 test=# \di ; List of relations Schema | Name | Type | Owner | Table --------+----------+-------+---------+------- public | idx_name | index | postgre | t public | idx_t | index | postgre | t_t (2 rows)
test=# drop table t_t; DROP TABLE
test=# CREATE USER svoid; CREATE ROLE # 创建sovid 指定密码 test=# CREATE USER svoid WITH PASSWORD '123qwe'; CREATE ROLE
test=# SELECT usename FROM pg_user; usename --------- postgre svoid (2 rows) test=# \du; List of roles Role name | Attributes | Member of -----------+------------------------------------------------+----------- postgre | Superuser, Create role, Create DB, Replication | {} svoid | | {}
test=# DROP USER svoid; DROP ROLE
test=# \dn; List of schemas Name | Owner --------+--------- public | postgre (1 row)
test=# CREATE SCHEMA myschema; CREATE SCHEMA
test=# DROP SCHEMA myschema; DROP SCHEMA
以上是“PostgreSQL常用命令有哪些”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流