这篇文章主要介绍PostgreSQL常用命令有哪些,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
查看版本信息
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
(1 row)
创建schema
test=# CREATE SCHEMA myschema;
CREATE SCHEMA
删除schema
test=# DROP SCHEMA myschema;
DROP SCHEMA
以上是“PostgreSQL常用命令有哪些”这篇文章的所有内容,感谢各位的阅读!
大型站长资讯类网站! https://www.0757zz.cn