Linux下安装PostgreSQL 转载linux社区
Linux下安装PostgreSQL
| [日期:2016-12-25] | 来源:Linux社区 作者:xiaojian | [字体:大 中 小] |
在Linux下安装PostgreSQL有二进制格式安装和源码安装两种安装方式,这里用的是二进制格式安装。各个版本的Linux都内置了PostgreSQL,所以可直接通过命令行安装便可。本文用的是CentOS 6.5。
安装Postgresql
--------------------------------------------------------------------------------
# 安装postgresql服务器
yum install postgresql-server
#依赖包是否安装
Y/N Y
#第三方贡献包
yum install postgresql-contrib
#依赖包是否安装
Y/N Y
安装成功后,数据库状态
[root@localhost Hadoop]# service postgresql status
postmaster is stopped
尝试启动数据库,但报错,需要先初始化数据目录
[root@localhost hadoop]# service postgresql start
/var/lib/pgsql/data is missing.Use "service postgresql initdb" to initialize the cluster first.
[root@localhost hadoop]# service postgresql initdb
Initializing database: [OK]
启动数据库
--------------------------------------------------------------------------------
通过service命令启动Postgresql,需要注意的是,默认在安装时会创建postgres用户并安装到此用户下。而Postgresql 的默认数据库也是用此用户命名的。
[root@localhost hadoop]# service postgresql start
Starting postgresql service: [ OK ]
[root@localhost hadoop]# su - postgres
-bash-4.1$ psql
psql (8.4.20)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collation | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/postgres
(3 rows)
postgres=#
Postgresql 的Psql 就等于Oracle的Sqlplus一样 ,直接用命令Psql登录等于用操作系统验证登录,不需要输入用户名和密码。
基本参数设置
--------------------------------------------------------------------------------
在Centos下,默认的数据目录在 /var/lib/pgsql/data 下 ,配置的参数文件就在此目录下。
-bash-4.1$ ls -l
total 80
drwx------ 5 postgres postgres 4096 Nov 16 07:43 base
drwx------ 2 postgres postgres 4096 Nov 17 23:51 global
drwx------ 2 postgres postgres 4096 Nov 16 07:43 pg_clog
-rw------- 1 postgres postgres 3533 Nov 17 22:05 pg_hba.conf
-rw------- 1 postgres postgres 1631 Nov 16 07:43 pg_ident.conf
drwx------ 2 postgres postgres 4096 Nov 18 00:00 pg_log
drwx------ 4 postgres postgres 4096 Nov 16 07:43 pg_multixact
drwx------ 2 postgres postgres 4096 Nov 18 00:00 pg_stat_tmp
drwx------ 2 postgres postgres 4096 Nov 16 07:43 pg_subtrans
drwx------ 2 postgres postgres 4096 Nov 16 07:43 pg_tblspc
drwx------ 2 postgres postgres 4096 Nov 16 07:43 pg_twophase
-rw------- 1 postgres postgres 4 Nov 16 07:43 PG_VERSION
drwx------ 3 postgres postgres 4096 Nov 16 07:43 pg_xlog
-rw------- 1 postgres postgres 16877 Nov 17 21:54 postgresql.conf
-rw------- 1 postgres postgres 57 Nov 17 23:51 postmaster.opts
-rw------- 1 postgres postgres 45 Nov 17 23:51 postmaster.pid
配置远程登录数据库
1. 修改 postgresql.conf 文件,配置PostgreSQL数据库服务器的相应的参数
listen_addresses = '*' # PostgreSQL安装完成后,默认是只接受来在本机localhost的连接请求,此处将数据库服务器的监听模式修改为监听所有主机发出的连接请求
port = 5432 # 默认端口,修改后要重启数据库
2. 修改 pg_hba.conf 文件,配置对数据库的访问权限

在最后一行加上配置,表示允许网段192.168.191.0上的所有主机使用所有合法的数据库用户名访问数据库,
24是子网掩码,表示允许IP范围在 192.168.191.0--192.168.191.255 的计算机访问。
3. 测试远程登录
首先修改默认数据库用户登录密码
-bash-4.1$ psql
psql (8.4.20)
Type "help" for help.
postgres=# \password
按提示修改密码。
然后再从另一台局域网机器上登录
psql -U postgres -d postgres -h 192.168.191.5 -p 5432 -- 成功
其中 –u 指定用户,-d 指定数据库名 ,-h 指定host,-p 端口号,按提示输入密码。
另外,可视化客户端推荐用DBeaver。

Linux下安装PostgreSQL 转载linux社区的更多相关文章
- (转)Linux下安装rar fou linux
在Linux下安装rar fou linux rar for linux 软件下载地址:http://www.rarsoft.com/download.htm 到目前为止最新的版本为4.10 beta ...
- linux下安装nodejs及linux下解压tar.xz文件
1.下载nodejs的安装包 2.解压该文件 在linux下,大部分情况下不能直接解压tar.xz的文件. 需要用xz -d xxx.tar.xz 将 xxx.tar.xz解压成 xxx.tar 然 ...
- linux下安装postgresql
环境:Linux localhost.localdomain 2.6.32-431 GNU/Linux x86_64 Postgresql版本:postgresql.9.5.3 添加开启自启设置:ht ...
- linux 下安装PostgreSql 并配置远程访问
1.官网下载PostgreSql 安装包 (https://www.enterprisedb.com/downloads/postgres-postgresql-downloads) 我下载的是 9. ...
- postgreSQL学习(一):在Linux下安装postgreSQL
1. 安装源: $ sudo yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgd ...
- Linux下安装 Posgresql 并设置基本参数
在Linux下安装Postgresql有二进制格式安装和源码安装两种安装方式,这里用的是二进制格式安装.各个版本的Linux都内置了Postgresql,所以可直接通过命令行安装便可.本文用的是Cen ...
- linux下安装mysql问题总结(一)mysqld_safe mysqld from pid file /usr/local/mysql/data/mysql.pid ended
linux下安装mysql数据库 linux版本:CentOS release 6.8 (Final) mysql版本:mysql-5.7.16-linux-glibc2.5-x86_64.tar.g ...
- 【转载】Linux下安装LoadRunner LoadGenerator
原文地址:[转载]Linux下安装LoadRunner LoadGenerator作者:邱建忠tester LR的负载机安装在linux的理由: 1.windows xp,双核+4G内存,基本上每个v ...
- (转载)Linux下安装配置MySQL+Apache+PHP+WordPress的详细笔记
Linux下安装配置MySQL+Apache+PHP+WordPress的详细笔记 Linux下配LMAP环境,花了我好几天的时间.之前没有配置过,网上的安装资料比较混乱,加上我用的版本问题,安装过程 ...
随机推荐
- python 算法学习部分代码记录篇章1
# -*- coding: utf-8 -*- # @Date : 2017-08-19 20:19:56 # @Author : lileilei '''那么算法和数据结构是什么呢,答曰兵法''' ...
- vue过滤数字为2位小数点,过滤器
过滤数字为2位小数点 filters: { //保留2位小数点过滤器 不四舍五入 number(value) { var toFixedNum = Number(value).toFixed(3); ...
- @NotEmpty、@NotBlank、@NotNull的区别
@NotEmpty 用在集合类上面 @NotBlank 用在String上面 @NotNull 用在基本类型上 只有简单的结果,但是再更具体一点的内容就搜不到了,所以去看了看源码,发现了如下的注释 ...
- K:枚举的线程安全性及其序列化问题
枚举是如何保证线程安全的且其在序列化和反序列化的操作中是单例的? 要想看源码,首先得有一个类吧,那么枚举类型到底是什么类呢?是enum吗?答案很明显不是,enum就和class一样,只是一个关 ...
- 教你如何安装配置Windows7系统 IIS IIS7.5本地浏览测试网站 完整版介绍
大家都知道网站建设前期测试于浏览网站都喜欢用iis本地浏览来操作 那么为了方便大家自己来安装和配置Internet信息服务 相信大家,对于Windows 7有了相应的了解,从操作上,使用上,内置功能上 ...
- 深入C#.NET数据类型
深入C#数据类型 --不同类型的参数传递使用值传递,在方法中对参数的更改在调用后不能保留.使用ref方式传递,可以保留对参数值的更改. ---值方式参数传递和引用方式传递使用值方式(不用ref修饰)传 ...
- robotframework学习笔记(七)------筛选执行用例
第一种:手动勾选用例 可勾选用户,然后点击运行,这样就只运行到勾选的用例.如果不勾选的点击运行就会运行所有用例. 第二种 菜单中去筛选 可在菜单中去筛选勾用例,然后点击运行 Select All Te ...
- springMVC(7)---表单标签
springMVC(7)---表单标签 form标签作用 简单来讲form表单有两大作用 1:第一就是往后端提交数据或者前端回显 ...
- jQuery源码解析资源便签
最近开始解读jQuery源码,下面的链接都是搜过来的,当然妙味课堂 有相关的一系列视频,长达100多期,就像一只蜗牛慢慢爬, 至少品读三个框架,以后可以打打怪,自己造造轮子. 完全理解jQuery源代 ...
- 入门干货之Electron的.NET实现-Electron.NET
0x01.Electron.NET 1.介绍 Electron是由Github上的一支团队和一群活跃贡献者维护.用HTML,CSS和JavaScript来构建跨平台桌面应用程序的一个开源库. Elec ...