Postgresql基础
跳到导航
跳到搜索
PostgreSQL is available in all Ubuntu versions by default.
Install
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - sudo apt-get update sudo apt-get -y install postgresql
安装完毕后,系统会创建一个数据库超级用户 postgres,密码为空。
DBA
Start
# 需要 root 权限 /etc/init.d/postgresql start | stop | restart systemctl start | stop | restart | status postgresql
执行SQL
psql -c "$SQL"
show databases
\l select * from pg_database;
connect databases
\c postgres
show tables
\dt \dt+ # 表类型、大小