centos7下postgresql数据库安装及配置
1、安装
#yum install -y postgresql-server
2、postgresql数据库初始化
#service postgresql initdb
3、启动postgresql服务
#systemctl start postgresql
#systemctl enable postgresql
4、查看postgresql状态
#netstat -tlunp|grep 5432
#ss -tlunp|grep 5432
5、连接postgresql数据库
想连接到数据库,需要切换到postgres用户(默认情况下,安装postgresql时会自动生成),使用psql连接到数据库中,在该用户下连接数据库,是不需要密码的。
#查看生成的用户
# tail -1 /etc/passwd
postgres:x:26:26:PostgreSQL Server:/var/lib/pgsql:/bin/bash
#切换用户,登录postgresql
[root@centos7 data]# su - postgres
Last login: Thu Oct 24 16:06:34 CST 2019 on pts/1
-bash-4.2$ psql #使用psql登录数据库
psql (9.2.24)
Type "help" for help.
postgres=# \l #列出所有数据库,相当于show databases;
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+-----------+---------+-------+-----------------------
postgres | postgres | SQL_ASCII | C | C |
template0 | postgres | SQL_ASCII | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | SQL_ASCII | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
(3 rows)
postgres=# \q #退出数据库
-bash-4.2$
6、postgresql的简单配置
postgresql数据库的配置主要是通过修改数据目录下的postgresql.conf文件来实现的
# ll /var/lib/pgsql/data/ #yum安装时路径
total 48
drwx------. 5 postgres postgres 41 Oct 24 15:49 base
drwx------. 2 postgres postgres 4096 Oct 24 15:50 global
drwx------. 2 postgres postgres 18 Oct 24 15:49 pg_clog
-rw-------. 1 postgres postgres 4232 Oct 24 15:49 pg_hba.conf
-rw-------. 1 postgres postgres 1636 Oct 24 15:49 pg_ident.conf
drwx------. 2 postgres postgres 32 Oct 24 15:49 pg_log
drwx------. 4 postgres postgres 36 Oct 24 15:49 pg_multixact
drwx------. 2 postgres postgres 18 Oct 24 15:50 pg_notify
drwx------. 2 postgres postgres 6 Oct 24 15:49 pg_serial
drwx------. 2 postgres postgres 6 Oct 24 15:49 pg_snapshots
drwx------. 2 postgres postgres 25 Oct 24 16:26 pg_stat_tmp
drwx------. 2 postgres postgres 18 Oct 24 15:49 pg_subtrans
drwx------. 2 postgres postgres 6 Oct 24 15:49 pg_tblspc
drwx------. 2 postgres postgres 6 Oct 24 15:49 pg_twophase
-rw-------. 1 postgres postgres 4 Oct 24 15:49 PG_VERSION
drwx------. 3 postgres postgres 60 Oct 24 15:49 pg_xlog
-rw-------. 1 postgres postgres 19805 Oct 24 15:49 postgresql.conf
-rw-------. 1 postgres postgres 57 Oct 24 15:50 postmaster.opts
-rw-------. 1 postgres postgres 92 Oct 24 15:50 postmaster.pid
7、修改监听的Ip和端口
#vim /var/lib/pgsql/data/postgresql.conf
59 #listen_addresses = 'localhost' # what IP address(es) to listen on;
60 # comma-separated list of addresses;
61 # defaults to 'localhost'; use '*' for all
62 # (change requires restart)
63 #port = 5432 # (change requires restart)
修改端口时,默认把前面#去掉,不修改的话默认为5432
#修改完后重启服务
#systemctl restart postgresql
8、修改数据库log相关的参数
# - Where to Log -
#log_destination = 'stderr' # Valid values are combinations of
# stderr, csvlog, syslog, and eventlog,
# depending on platform. csvlog
# requires logging_collector to be on.
# This is used when logging to stderr:
logging_collector = on # Enable capturing of stderr and csvlog
#日志默认为打开
# into log files. Required to be on for
# csvlogs.
# (change requires restart)
# These are only used if logging_collector is on:
#log_directory = 'pg_log' # directory where log files are written,
# can be absolute or relative to PGDATA
log_filename = 'postgresql-%a.log' # log file name pattern,
# can include strftime() escapes
#log_file_mode = 0600 # creation mode for log files,
# begin with 0 to use octal notation
log_truncate_on_rotation = on # If on, an existing log file with the
# same name as the new log file will be
# truncated rather than appended to.
# But such truncation only occurs on
# time-driven rotation, not on restarts
# or size-driven rotation. Default is
# off, meaning append to existing files
# in all cases.
log_rotation_age = 1d # Automatic rotation of logfiles will
#日志只保存一天
# happen after that time. 0 disables.
log_rotation_size = 0 # Automatic rotation of logfiles will
# happen after that much log output.
# 0 disables.
9、内存参数的设置
# - Memory -
shared_buffers = 32MB # min 128kB
#共享内存的大小,用于共享数据块
10、添加用户、创建数据库、并登录
#授权用户远程登录
#vim /var/lib/pgsql/data/pg_hba.conf #在最后一行添加
host all all 0.0.0.0/0 md5
#vim /var/lib/pgsql/data/postgresql.conf
listen_addresses='*' #把localhost更改为*
#systemctl restart postgresql
#创建用户和密码
postgres=# create user wang01 with password '123456';
CREATE ROLE
#创建数据库,基于用户wang01
postgres=# create database test01 owner wang01;
CREATE DATABE
#授权用户
postgres=# grant all privileges on database test01 to wang01;
GRANT
#查看结果
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+-----------+---------+-------+-----------------------
postgres | postgres | SQL_ASCII | C | C |
template0 | postgres | SQL_ASCII | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | SQL_ASCII | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
test | wang | SQL_ASCII | C | C | =Tc/wang +
| | | | | wang=CTc/wang
test01 | wang01 | SQL_ASCII | C | C | =Tc/wang01 +
| | | | | wang01=CTc/wang01
test02 | postgres | SQL_ASCII | C | C |
(6 rows)
#登录
[root@centos7 data]# psql -h 10.0.0.3 -p 5432 -U wang -d test
Password for user wang:
psql (9.2.24)
Type "help" for help.
test=> \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+-----------+---------+-------+-----------------------
postgres | postgres | SQL_ASCII | C | C |
template0 | postgres | SQL_ASCII | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | SQL_ASCII | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
test | wang | SQL_ASCII | C | C | =Tc/wang +
| | | | | wang=CTc/wang
(4 rows)
11、postgresql数据库基本应用
1、列出所有数据库
mysql: show databases
psql: \l或\list
2、切换数据库
mysql: use dbname
psql: \c dbname
3、列出当前数据库下的所有表
mysql: show tables
psql: \d
4、列出指定表的所有字段
mysql: shwo columns from table_name
psql: \d table_name
5、查看表的基本情况
mysql: describe table_name
psql: \d+ table_name
centos7下postgresql数据库安装及配置的更多相关文章
- CentOS7下MariaDB数据库安装及配置
前言 MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品.在存 ...
- Centos7 下的SVN安装与配置
Centos7 下的SVN安装与配置 1.关闭防火墙 临时关闭防火墙 systemctl stop firewalld 永久防火墙开机自关闭 systemctl disable firewalld 临 ...
- CentOS7下NFS服务安装及配置固定端口
CentOS7下NFS服务安装及配置 系统环境:CentOS Linux release 7.4.1708 (Core) 3.10.0-693.el7.x86_64 软件版本:nfs-utils-1. ...
- centos下postgresql的安装与配置[转]
本文摘自:http://blog.chinaunix.net/uid-24846094-id-78490.html 一.安装(以root身份进行) 1.检出最新的postgresql的yum配置从ht ...
- CentOS 6.3下PostgreSQL 的安装与配置
一.简介 PostgreSQL 是一种非常复杂的对象-关系型数据库管理系统(ORDBMS),也是目前功能最强大,特性最丰富和最复杂的自由软件数据库系统.有些特性甚至连商业数据库都不具备.这个起源于伯克 ...
- CentOS下PostgreSQL的安装与配置
一.CentOS下PostgreSQL的yum安装: #安装yum源,默认源存在对版本的支持不好,下载不到等等问题. yum install http://yum.postgresql.org/9.5 ...
- Linux——CentOS 6.3下PostgreSQL 的安装与配置
一.简介 PostgreSQL 是一种非常复杂的对象-关系型数据库管理系统(ORDBMS),也是目前功能最强大,特性最丰富和最复杂的自由软件数据库系统.有些特性甚至连商业数据库 都不具备.这个起源于伯 ...
- centos7下git的安装和配置
git的安装: yum 源仓库里的 Git 版本更新不及时,最新版本的 Git 是 1.8.3.1,但是官方最新版本已经到了 2.9.2.想要安装最新版本的的 Git,只能下载源码进行安装. 1. 查 ...
- Linux下PostgreSQL 的安装与配置
一.简介 PostgreSQL 是一种非常复杂的对象-关系型数据库管理系统(ORDBMS),也是目前功能最强大,特性最丰富和最复杂的自由软件数据库系统.有些特性甚至连商业数据库都不具备.这个起源于伯克 ...
随机推荐
- jenkins+sonar发送结果邮件的状态问题修复
在我的这篇博文中:使用jenkins+sonar进行代码扫描,并发送自定义邮件 邮件的配置为默认的$PROJECT_DEFAULT_SUBJECT 所以发送的邮件标题中的状态是jenkins构建的状态 ...
- 移动端自动化测试之adb常用命令
今天我们来聊聊自动化测试过程中常用的adb命令. 简介 首先介绍下什么是adb,adb全称叫“android debug bridge”,翻译过来就叫调试桥,通过命令行指令,可让你与移动端设备进行相互 ...
- Golang 异常/日志处理
1.xerrors 异常 xerrors 包是一个非常棒的设计,不同于往常语言如java/php,因为go的errors只是一个string类型的映射,所以内存占用空间很少.这在golang的核心库和 ...
- SQL语句 常用记录
1,求平均,保留2位小数: ,)) as avg from {$table}; // amount为数据库某个字段 2,条件累加 , p1, )) AS cnt1 ; // 如果符合 cnt > ...
- [转帖]linux下的find文件查找命令与grep文件内容查找命令
linux下的find文件查找命令与grep文件内容查找命令 https://www.cnblogs.com/shileima/p/8431393.html 在使用linux时,经常需要进行文件查找. ...
- oracle多表关联查询和子查询
oracle多表关联查询和子查询 一.多表关联查询 例子: SQL> create table student1 ( sid ), sname ), sage )); Table created ...
- Oracle(11g)详细安装步骤
最详细的Oracle安装步骤就在这里,话不多说直接给大家上安装Oracle的详细教程 如果没有安装包,可以先点击下载下载地址:http://download.oracle.com/otn/nt/o ...
- javaIO -- File源码
一.简介 文件和目录路径名的抽象表示. 用户界面和操作系统使用依赖于系统的路径名字符串命名文件和目录. 这个类提供了一个抽象的,独立于系统的层次化路径名的视图. 二.代码 (一).属性详情 //平台的 ...
- [DEBUG] ubuntu mysql root@localhost改了密码还是进不去ERROR 1698 (28000)
之前用skip-grant-tables的方法免密进入Mysql,修改了root的密码, 当时重启服务后是可以用密码进入Mysql的.结果昨天突然又进不去了:) 所以更换方法,特此记录. ====== ...
- Python 【爬虫】
爬虫的工作原理 首先,爬虫可以模拟浏览器去向服务器发出请求: 其次,等服务器响应后,爬虫程序还可以代替浏览器帮我们解析数据: 接着,爬虫可以根据我们设定的规则批量提取相关数据,而不需要我们去手动提取: ...