postgres

官网 | PostgreSQL 教程

Postgresql常用操作

配置

su - postgres
#vim data/postgresql.conf
#设置可访问IP
listen_address = '*'

#vim data/pg_hba.conf
#设置可访问IP
host    all             all             0.0.0.0/0               md5

设置访问IP和访问模式md5
# TYPE  DATABASE        USER            ADDRESS                 METHOD
local   all             portgres                                md5
local   all             all                                     md5
host    all             all             127.0.0.1/32            md5
host    all             all             0.0.0.0/0               md5
host    all             all             ::1/128                 md5
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5

psql
\password postgres

psql -U postgres -h 127.0.0.1 -d jwedemo

root#vim ~/.pgpass
#host:port:database:username:password
localhost:5432:jwtdemo:postgres:password000

postgresql

sudo yum install postgresql postgresql-server -y
sudo postgresql-setup initdb
sudo systemctl enable postgresql
sudo systemctl start postgresql

sudo su postgres
#psql postgres
相当于下行命令:
sudo -u postgres psql postgres

sudo -i -u postgres
su - postgres

设置用户postgres密码
\password postgres

创建用户:
sudo -u postgres createuser username 

– List all the databases:
# \list
– Connect to a database:
# \c database_name
– List all the tables
# \d
- List a table
# \d jwtbase
- List installed plugins
# \dx
– Create a Database
# create database miniflux2;
# createdb database_name
# createdb database_name OWNER rolename;
– Create a table
# create table employees (name varchar(25), surname varchar(25));
– Insert records
# INSERT INTO employees VALUES ('Lotfi','waderni');
– Exit from PosgreSQL prompt:
# \q
#