GVKun编程网logo

关于linux上postgresql的一些理解

23

如果您对关于linux上postgresql的一些理解感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解关于linux上postgresql的一些理解的各种细节,此外还有关于centos7下源码编

如果您对关于linux上postgresql的一些理解感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解关于linux上postgresql的一些理解的各种细节,此外还有关于centos 7下源码编译安装php支持PostgreSQL postgresql手册 postgresql官网下载 postgresql视频教、linux – PostgreSQL的不同版本、Linux上Postgres Plus数据库备份和恢、Linux上POSTGRES操作的实用技巧。

本文目录一览:

关于linux上postgresql的一些理解

关于linux上postgresql的一些理解

刚开始接触postgresql,安装后就有一个默认用户postgres,而且在启动postgresql后只能通过切换到linux的postgres用户才能登录数据库进行操作,和MysqL的登录认证居然不一样。查了好多资料才知道,原来有个pg_hba.conf的配置文件作登录限制。它的语法规则是这样的:

  local database user auth-method [auth-options]

  host database user address auth-method [auth-options]

  hostssl database user address auth-method [auth-options]

  hostnossl database user address auth-method [auth-options]

  host database user IP-address IP-mask auth-method [auth-options]

  hostssl database user IP-address IP-mask auth-method [auth-options]

  hostnossl database user IP-address IP-mask auth-method [auth-options]

第一列是连接的方式,local是通过本地的unix socket连接,host是通过IP地址连接。第二列是目标数据库,第三列是用户。最后一列是认证方式(关键点),总共支持11种认证方式:

  1. Trust Authentication

  2. Password Authentication

  3. GSSAPI Authentication

  4. sspI Authentication

  5. Ident Authentication

  6. Peer Authentication

  7. LDAP Authentication

  8. RADIUS Authentication

  9. Certificate Authentication

  10. PAM Authentication

  11. BSD Authentication

其中最常见的就是peer,ident,password。

peer方式中,client必须和Postgresql在同一台机器上,并且需要当前系统用户和要登陆到Postgresql的用户名相同,就可以登陆。

ident与peer类似,不过peer只能在Postgresql本地使用,ident则可以跨主机使用。

其实我们最常用的方式是通过密码远程登陆:

password认证分为三种方式:scram-sha-256、md5、password。

这三种方式都用密码认证,区别是密码在Postgresql上存储的形式和登陆时密码的传输形式。

如:# IPv4 local connections: host all all 127.0.0.1/32 md5

注意:修改了pg_hba.conf之后,需要重启Postgresql,才会应用新配置。

centos 7下源码编译安装php支持PostgreSQL postgresql手册 postgresql官网下载 postgresql视频教

centos 7下源码编译安装php支持PostgreSQL postgresql手册 postgresql官网下载 postgresql视频教

1. 下载源码

$ mkdir /usr/downloads
$ wget -c http://cn2.php.net/distributions/php-5.6.20.tar.gz
$ tar -xvf php-5.6.20.tar.gz
$ mv php-5.6.20 /usr/local/src
$ cd !$ & cd php-5.6.20
登录后复制

2. 阅读安装指导

$ ls -also
$ less README
$ less INSTALL
登录后复制

3. 安装依赖包

$ yum install apr apr-util apr-devel apr-util-devel prce lynx
登录后复制

4. 安装httpd

$ wget -c http://apache.fayea.com//httpd/httpd-2.4.20.tar.gz
$ tar -xvf httpd-2.4.20.tar.gz
$ cd httpd-2.4.20
$ ./configure \
--prefix=/usr/local/programs/apache2 \
--enable-rewrite \
--enable-so \
--enable-headers \
--enable-expires \
--with-mpm=worker \
--enable-modules=most \
--enable-deflate \
--enable-module=shared
$ make
$ make install
$ cd /usr/local/programs/apache2
$ cp bin/apachectl /etc/init.d/httpd ## 复制启动脚本
$ /etc/init.d/httpd start ## 启动apache服务器,访问http://localhost/
$ egrep -v ''^[ ]*#|^$'' /usr/local/apache2/conf/httpd.conf | nl ## 查看apache服务器的配置
## 将apache加入系统服务
vi /etc/rc.d/rc.local
```
/usr/local/programs/apache2/bin/apachectl start
```
$ cat /etc/rc.local
登录后复制

4. 安装postgresql

立即学习“PHP免费学习笔记(深入)”;

$ yum install readline-devel  ## 安装readline依赖
$ cd /usr/downloads
$ wget -c https://ftp.postgresql.org/pub/source/v9.5.0/postgresql-9.5.0.tar.bz2
$ tar -xvf postgresql-9.5.0.tar.bz2
$ cd postgresql-9.5.0
$ ./configure --prefix=/usr/local/programs/postgresql
$ make
$ su
$ make install
$ /sbin/ldconfig /usr/local/programs/postgresql/lib ## 刷新下共享动态库
$ cd /usr/local/programs/postgresql
$ bin/psql --version  ## 检查运行情况
## 开始对postgresql的配置
$ vi /etc/profile.d/postgresql.sh ## 增加环境变量,不推荐直接在/etc/profile中添加,系统更新升级时会需要merge
``` 
PATH=/usr/local/programs/postgresql:$PATH
export PATH
```
$ source /etc/profile ## 更新环境变量

## 增加用户和其他文件夹
$ adduser postgres
$ passwd postgres 
$ mkdir /usr/local/programs/postgresql/logs
$ mkdir /usr/local/programs/postgresql/data
$ chown postgres /usr/local/programs/postgresql/data
$ su - postgres

## 初始化数据库
$ ./bin/initdb -D ./data
$ ./bin/createdb test
$ ./bin/psql test
## 已有数据库,可导入data文件夹后尝试root访问,假如带密码,可能需要进一步研究下
$ ./bin/postgres -D ./data >./logs/start-log-1.log 2>&1 &
$ ./bin/psql --list  ##列出数据库
## ok,安装完成

## 自定义设置,权限控制等,可以跳过,等熟悉使用后再做
## 编辑数据库配置及权限文件:
$ vi /usr/local/programs/postgresql/data/postgresql.conf   ## 数据库配置文件
$ chown postgres postgresql.conf
$ chmod 644 postgresql.conf
$ vi /usr/local/programs/postgresql/data/pg_hba.conf   ## 权限文件
$ vi /usr/local/programs/postgresql/data/pg_ident.conf

## 设置开机自启动:
$ vi /etc/rc.d/rc.local    ## 添加如下内容
```
/usr/local/programs/postgresql/bin/postgresql start
```
登录后复制

5. 安装php

## 源码已经在第一步中下载,现在开始安装:
$ yum install libxml2 libxml2-devel libpng libpng-devel libjpeg libjpeg-devel freetype freetype-devel
$ ./configure \
--prefix=/usr/local/programs/php \
--with-apxs2=/usr/local/programs/apache2/bin/apxs \
--with-zlib \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-zlib-dir \
--enable-mbstring \
--with-pgsql=/usr/local/programs/postgresql \
--with-pdo-pgsql=/usr/local/programs/postgresql 
$ make
$ make test
> Bug #42718 (unsafe_raw filter not applied when configured as default filter) [ext/filter/tests/bug42718.phpt]  XFAIL REASON: FILTER_UNSAFE_RAW not applied when configured as default filter, even with flags
> Bug #67296 (filter_input doesn''t validate variables) [ext/filter/tests/bug49184.phpt]  XFAIL REASON: See Bug #49184
> Bug #53640 (XBM images require width to be multiple of 8) [ext/gd/tests/bug53640.phpt]  XFAIL REASON: Padding is not implemented yet
> zend multibyte (7) [ext/mbstring/tests/zend_multibyte-07.phpt]  XFAIL REASON: https://bugs.php.net/bug.php?id=66582
> zend multibyte (9) [ext/mbstring/tests/zend_multibyte-09.phpt]  XFAIL REASON: https://bugs.php.net/bug.php?id=66582
>Bug #70470 (Built-in server truncates headers spanning over TCP packets) [sapi/cli/tests/bug70470.phpt]  XFAIL REASON: bug is not fixed yet

## 查阅官方的bug,发现:
> id=66582: status : Closed. Fixed in master (PHP7)
> id=42718: status : Assigned
> id=42718: reference to id=49184, unsolved for many years
## 那就不关心了,直接装吧
$ make install
> You may want to add: /usr/local/programs/php/lib/php to your php.ini include_path

## 那就按它说的设置吧
$ cp php.ini-development /usr/local/programs/php/lib/php.ini
```
include_path = ".;/usr/local/programs/php/lib/php"

## 然后,编辑httpd的设置,确保其能正确解析php文件
```
...
LoadModule php5_module modules/libphp5.so
...
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .php5

...
<ifmodule dir_module>
    DirectoryIndex index.html index.php
</ifmodule>     
```

## 重启httpd,测试
$ cd /usr/local/programs/apache2
$ bin/httpd -h
$ bin/httpd -k stop
$ bin/httpd -f conf/httpd.conf
## 默认设置的www页面在./htdocs/下,那就先去里面建一个测试页面吧
$ vi htdocs/index.php
```
<?php phpinfo(); ?>
```
$ curl http://localhost/index.php |grep postgresql
#ok
登录后复制

后续应该做的事

* 1. 启动时,不需要要手动指定配置文件
* 2. php初始化www目录设置
* 3. php 用户、权限管理等

'').addClass(''pre-numbering'').hide(); $(this).addClass(''has-numbering'').parent().append($numbering); for (i = 1; i '').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了centos 7下源码编译安装php支持PostgreSQL,包括了postgresql,centos 7方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

linux – PostgreSQL的不同版本

linux – PostgreSQL的不同版本

我是Postgresql的新手,并希望开始使用它作为Web开发的数据库.
但是在Postgresql网站上我有4个活跃版本:9.2,9.1,9.0和8.4.

为什么Postgresql有4个有效版本?
它们之间的主要区别是什么?
我应该去最新的吗?

提前致谢.

解决方法

在这种情况下活跃意味着他们仍在维持;错误修复,安全修复.生命结束/失去支持的事情不再列出.就是这样.

您可以通过阅读version policy文档了解更多信息.

是的,如果你没有可能破坏的遗留物,那么去最新的是一个相当安全的选择.

Linux上Postgres Plus数据库备份和恢

Linux上Postgres Plus数据库备份和恢

本文将为读者介绍如何使用pg_dump和pg_restore来保护Postgres Plus数据库。我们会向您介绍如何构建数据库和应用程序,怎样周

  本文将为读者介绍如何使用pg_dump和pg_restore来保护Postgres Plus数据库。我们会向您介绍如何构建数据库和应用程序,,怎样周期性创建数据库备份的方法,并在需要的时候修复它们。

  一、引言

  本文将为读者详解在linux环境中快速玩转Postgres Plus Standard Server或者Postgres Plus Advanced Server数据库产品的必要知识,在此之前,我们假定您已经下载并且安装好了Postgres Plus Standard Server 或者Postgres Plus Advanced Server。这将有助于您加快对于Postgres Plus Standard Server或者Postgres Plus Advanced Server的技术评估。

  通过本文,您将能够掌握下列技能:

  ?熟悉不同的备份格式

  ?选择不同的备份和恢复选项

  ?使用纯文本进行备份和恢复

  ?为备份和恢复创建一个定制的归档

linux

Linux上POSTGRES操作

Linux上POSTGRES操作

登录
$ psql (连接数据库,默认用户和数据库都是postgres)
$ psql -U <user> -d <dbname> 

 

数据库操作

// 列举数据库,相当于show databases

$ \l

 // 切换数据库,相当与use dbname

$ \c <dbname>

 // 列举表,相当与show tables  

$ \dt

 // 查看表结构,相当于desc

$ \d tblname

// 创建数据库

$ create database <dbname>

 // 删除数据库

$ drop database <dbname>

// 创建表

$ create table ([字段名1] [类型1] ;,[字段名2] [类型2],......<,primary key (字段名m,字段名n,...)>;); 

 // 在表中插入数据

$ insert into 表名 ([字段名m],[字段名n],......) values ([列m的值],[列n的值],......);

 // 备份数据库

$ pg_dump -U postgres -f /tmp/postgres.sql postgres (导出postgres数据库保存为postgres.sql)
$ pg_dump -U postgres -f /tmp/postgres.sql -t test01 postgres (导出postgres数据库中表test01的数据)
$ pg_dump -U postgres -F t -f /tmp/postgres.tar postgres (导出postgres数据库以tar形式压缩保存为postgres.tar)

 // 恢复数据库

$ psql -U postgres -f /tmp/postgres.sql bk01 (恢复postgres.sql数据到bk01数据库)
$ pg_restore -U postgres -d bk01 /tmp/postgres.tar  (恢复postgres.tar数据到bk01数据库)

 

用户操作

// 切换用户

$ \c - <username>

 // 创建用户并设置密码

$ CREATE USER ‘username‘ WITH PASSWORD ‘password‘;
$ CREATE ROLE ‘username‘ CREATEDB PASSWORD ‘password‘ LOGIN; (创建角色并授予创建数据库及密码登录的属性)

 // 修改用户密码

$ ALTER USER ‘username‘ WITH PASSWORD ‘password‘;

 // 数据库授权

$ GRANT ALL PRIVILEGES ON DATABASE ‘dbname‘ TO ‘username‘;

 // 修改用户权限

$ ALTER ROLE ‘username‘ createdb ; (授予创建数据库权限)
$ ALTER ROLE ‘username‘ superuser ;(授予超级管理员权限)

 // 角色属性

login

login 只有具有 LOGIN 属性的角色可以用做数据库连接的初始角色名。

superuser 

数据库超级用户 

createdb 

创建数据库权限 

createrole

允许其创建或删除其他普通的用户角色(超级用户除外) 

replication

 做流复制的时候用到的一个用户属性,一般单独设定。 

password

在登录时要求指定密码时才会起作用,比如md5或者password模式,跟客户端的连接认证方式有关 

inherit

用户组对组员的一个继承标志,成员可以继承用户组的权限特性 

关于关于linux上postgresql的一些理解的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于centos 7下源码编译安装php支持PostgreSQL postgresql手册 postgresql官网下载 postgresql视频教、linux – PostgreSQL的不同版本、Linux上Postgres Plus数据库备份和恢、Linux上POSTGRES操作等相关知识的信息别忘了在本站进行查找喔。

本文标签: