- 数据库
type: channel
link: http://www.lithum.tech/index.php/category/%E6%95%B0%E6%8D%AE%E5%BA%93/
items: PostgreSQL安装配置

PostgreSQL安装配置
type: item
date: 2021-12-05T11:20:00+08:00
description: 安装PostgreSQL14安装PostgreSQL14在官网上有介绍。非常全面。我们这里使用CentOS7:::bash # Install the repository RPM: sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm # Install PostgreSQL: sudo yum install -y postgresql14-server # Optionally initialize the database and enable automatic start: sudo /usr/pgsql-14/bin/postgresql-14-setup initdb sudo systemctl enable postgresql-14 sudo systemctl start postgresql-14 登录数据库切换用户，运行psql[root@centos7 ~]# su postgres bash-4.2$ psql could not change directory to "/root": Permission denied psql (14.1) Type "help" for help.下面包括一些常用操作\l # 列出所有数据库 \c 数据库 # 连接数据库 \d # 列出所有表 \d 表名 # 列表所有列 \q # 退出数据库 ctrl+d数据库常用操作创建与删除数据库create database xuanmingyi; drop database xuanmingyi;创建与删除表create table company(id int primary key not null, name text not null, age int not null); drop table company;数据操作插入insert into company (id, name, age) values (1, 'xxx', 12);更新update company set name='xmy' where id=1;查找select * from company where id = 1;删除delete from company where id = 1;用户以及权限创建用户使用postgres用户登录postgresqlcreate user xmy with password '123456'; create database xmydb owner xmy; grant all privileges on database xmydb to xmy;在Linux系统中添加用户adduser xmy切换用户su xmy psql -d xmydb远程访问授权修改配置文件/var/lib/pgsql/14/data/postgresql.conflisten_addresses = '*'修改配置文件/var/lib/pgsql/14/data/pg_hba.conf# TYPE DATABASE USER ADDRESS METHOD host all all 0.0.0.0/0 md5可以远程连接啦