PostgreSQL 使用

Tags
linuxdatabasemacos
Created
Oct 11, 2018 9:41 AM

pgx 写扩展:https://mp.weixin.qq.com/s/FslSvvtM37O5cRxfhZ1XUw

PostgreSQL 会新建一个名为 postgres 的用户

迁移:

su - postgres #  sudo -i -u postgres #???// psql -U postgres

pg_dump [database_name] > ~/db.dump # 或者 db.sql

psql [database_name] -U [username] < ~/db.dump

psql(包含 psql command 和 SQL command):

查看角色 postgres=# \du

查看数据库 postgres=# \l

切换数据库 postgres=# \c exampledb

切换用户 postgres=# \c - username

列出数据库所有表 postgres=# \d

查看指定表结构 postgres=# \d user_tab1

创建角色 postgres=# CREATE ROLE <username> WITH LOGIN PASSWORD '<password>';

添加权限 postgres=# ALTER ROLE <username> CREATEDB;

设置密码 postgres=# \password <username>

创建数据库 postgres=# CREATE DATABASE super_awesome_application;

查询 SELECT tablename FROM pg_tables;

删除 DELETE FROM EMPLOYEES WHERE ID = 1;

https://www.codementor.io/engineerapart/getting-started-with-postgresql-on-mac-osx-are8jcopb

进入 psql:sudo psql postgres

brew install postgresql

pg_ctl -D /usr/local/var/postgres start # 开启数据库

createuser --createdb mt

createdb -U mt super_awesome_application

图形化工具:https://eggerapps.at/postico/

Ubuntu:

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-16-04

安装: sudo apt-get install postgresql postgresql-contrib

进入 psql :sudo -u postgres psql

用户验证报错 ident authentication failed for user postgres:https://stackoverflow.com/a/46907674/7167456

// 再进 postgres 用户重启配置:pg_ctl reload

数据类型:https://www.runoob.com/postgresql/postgresql-data-type.html

修改:https://www.techonthenet.com/postgresql/tables/alter_table.php

SuperMade with Super