Ubuntu Linux 下编译安装 PostgreSQL 和 pgAdmin

本文假设读者已经分别下载解压出 

PostgreSQL 9.1 (http://www.postgresql.org/ftp/source/v9.1.6/)

pgAdmin3 (http://www.postgresql.org/ftp/pgadmin3/release/v1.16.0/src/)


PostgreSQL 9.1 安装路径:/usr/local/pgsql/9.1

pgAdmin3 安装路径:/usr/local/pgadmin3


一 安装 PostgreSQL

1. 在终端中执行以下命令

    sudo apt-get install zlib1g-dev

    sudo apt-get install libreadline-dev


2. 到 PostgreSQL 解压后的目录中进行编译

    cd $the_direcotry_of_postgresql

    ./configure

    make
    su
    make install

在此过程中,如果有提示 “Permission denied” 的错误信息,请重新解压 pgAdmin3 的压缩包,然后使用 sudo chown -R 和 sudo chgrp -R 修改 pgAdmin3 解压后的文件夹的用户和组为读者自己的用户和组。


3. 安装后的必备工作

    # PostgreSQL 不能以 root 用户运行,所以我们创建 postgres 用户

    adduser postgres
    mkdir /usr/local/pgsql/9.1/data
    chown postgres /usr/local/pgsql/9.1/data

    # 切换到 postgres 用户

    su - postgres

    # 初始化

    /usr/local/pgsql/9.1/bin/initdb -D /usr/local/pgsql/9.1/data

    touch /usr/local/pgsql/9.1/data/logfile

    # 让 PostgreSQL 在后台运行

    /usr/local/pgsql/9.1/bin/postgres -D /usr/local/pgsql/9.1/data > /usr/local/pgsql/9.1/data/logfile 2>&1 &


4. 创建测试数据库 test

    # 下面这条语句执行后,PostgreSQL 会返回 “ CREATED DATABASE”的信息,

    # 表明数据库建立完成

    /usr/local/pgsql/9.1/bin/createdb test

    # 进入test数据库

    /usr/local/pgsql/9.1/bin/psql test

 # 输入建表语句:

 CREATE TABLE mytable (id VARCHAR(20), name VARCHAR(30));

    # 建立完成后,会得到一条 “CREATED” 的信息,表示建立成功。

    # 现在插入一条数据:

  INSERT INTO mytable VALUES('author', 'alice');

  # psql 返回类似 INSERT 18732 1

    # 查询插入是否成功:

    SELECT * FROM mytable;

    # 退出 psql : 

    \q


5. 退出

    # 退出 postgres 用户

    exit

    # 退出 root 用户

    exit


[

6. 如何关闭 PostgreSQL

    # 切换到 postgres 用户

    su - postgres

    # 关闭 PostgreSQL

    /usr/local/pgsql/9.1/bin/pg_ctl stop -D /usr/local/pgsql/9.1/data

    # 退出 postgres 用户

    exit


]

--------------------------------------------------------------------------------


二 安装 pgAdmin3
1. 安装必要的库
    sudo apt-get install libxml2-dev

    sudo apt-get install libxslt1-dev

    sudo apt-get install libpq-dev


    sudo apt-get install wx-common libwxgtk2.8-dev


2. 如果 /usr/lib 下有 libcrypto.so,请跳过2执行3,否则:

    cd /usr/lib
    # 创建链接,libcrypto.so.x.y.z 是你的 /usr/lib 下已有的某个版本的crypto动态库文件名
    sudo ln -s libcrypto.so.x.y.z libcrypto.so


3. 切换到你的 pgAdmin3 解压后的目录后编译安装 pgAdmin3

    cd $the_directory_of_pgadmin3

    ./configure
    make all
    sudo make install

在此过程中,如果有提示 “Permission denied” 的错误信息,请重新解压 pgAdmin3 的压缩包,然后使用 sudo chown -R 和 sudo chgrp -R 修改 pgAdmin3 解压后的文件夹的用户和组为读者自己的用户和组。


4. 运行 pgAdmin3

    cd /usr/local/pgadmin3/bin

    sudo ./pgadmin3


--------------------------------------------------------------------------------


三 扩展阅读:

PostgreSQL

维基百科,自由的百科全书
PostgreSQL

Postgresql elephant.svg
开发者PostgreSQL Global Development Group
稳定版本9.1.4/
2012年6月4日;2个月前
操作系统跨平台
类型RDBMS
许可协议BSD
站点www.postgresql.org

PostgreSQL自由的对象-关系数据库服务器(数据库管理系统),

在灵活的BSD-风格许可证下发行。

它在其他开放源代码数据库系统(比如MySQLFirebird),

专有系统比如OracleSybase

IBM的DB2Microsoft SQL Server之外,为用户又提供了一种选择。

PostgreSQL不寻常的名字导致一些读者停下来尝试拼读它,

特别是那些把SQL拼读为"sequel"的人。

PostgreSQL开发者把它拼读为"post-gress-Q-L"。

它也经常被简略念为"postgres"。


Installing the GNU Readline library

If you wish to compile with Readline support and your unix-like systemdoes not have the Readline library installed, follow the tips here tohelp with Readline installation. Most Linux installations will havethe readline library installed already and all you need to do isuncomment the two lines in the Makefile:

      READLINE    = -DREADLINE_SUPPORT
      READLINELIB = -lreadline -lcurses

On recent versions of Linux, if this doesn't work, then you may haveto install the readline development libraries with a command like:

      yum install readline-devel         (RPM-based systems)
      apt-get install libreadline5-dev   (Debian-based systems)

If this doesn't work, or you are using another Unix system thenproceed as follows:

Download the latest version of GNU readline fromhttp://cnswww.cns.cwru.edu/php/chet/readline/rltop.html At the time of writing, this is readline-6.0.tar.gz

Unpack the gzipped tar file under /tmp

      cd /tmp
      tar -zxvf readline-6.0.tar.gz

Change to the directory this creates and run configure:

      cd readline-6.0
      ./configure

If you do not have write access to the /usr/local/ hierarchy,then you can install the files somewhere else:

      ./configure --prefix=/home/my-user-name/packages

Now build the readline library

      make

and install (become superuser first if installing under /usr/local)

      make install

Now, ensure that the directory where the library has been installed(/usr/local/lib/ by default) is in the search path. You can do thisby setting the environment variable LD_LIBRARY_PATH

(csh)   setenv LD_LIBRARY_PATH /usr/local/lib
(sh)    export LD_LIBRARY_PATH=/usr/local/lib

Alternatively, if you have root access, you can edit the file/etc/ld.so.conf to add the directory in which the library has beeninstalled. Under recent Linux installations, there is anotheralternative which is to create a file /etc/ld.so.conf.d/readline.confjust containing a single line with the directory where the library hasbeen installed. In either case, you must now (as root) type the command:

      /sbin/ldconfig

Now, modify the Makefile, such that this directory is in the linker'slibrary path. Change:

      READLINELIB = -lreadline -lcurses

to:

      READLINELIB = -L/usr/local/lib -lreadline -lcurses

Now build with make as usual, but endure that LD_LIBRARY_PATH is set whenever you want to run the program. Alternatively, installwith

      ./configure --prefix=/usr/lib

to install in the main system directories and then it will be in thedefault search path. This isn't recommended unless you know what youare doing!

You can also link the readline library statically to ensureportability to machines with Linux machines having different versionsof the readline library installed. In this case you will not need theLD_LIBRARY_PATH or changes to /etc/ld.so.conf. To dothis, edit the Makefile and change:

      READLINELIB = -lreadline -lcurses

to

      READLINELIB = /usr/lib/libreadline.a -lcurses

(changing /usr/lib/ as required to point to wherever libreadline hasbeen installed).


--------------------------------------------------------------------------------


configure: error: readline librarynot  found

搭建Postgresql测试环境,在安装过程中遇到一个问题,在执行 configure
过程中报以下错误,configure: error: readline library not found, 但是在系统中已经安装
readline 包了:

1 环境信息
OS: CentOS release 5.2(Final)
PG: postgresql-9.0.0]

2 根据提示,我测试了下 configre命令,果然报这个错
[root@HK81-107postgresql-9.0.0]# ./configure
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking which template to use... linux
checking whether to build with 64-bit integer date/time support...yes
checking whether NLS is wanted... no
checking for default port number... 5432
checking for block size... 8kB
checking for segment size... 1GB
checking for WAL block size... 8kB
checking for WAL segment size... 16MB
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking if gcc supports -Wdeclaration-after-statement...yes
checking if gcc supports -Wendif-labels... yes
checking if gcc supports -fno-strict-aliasing... yes
checking if gcc supports -fwrapv... yes
checking whether the C compiler still works... yes
checking how to run the C preprocessor... gcc -E
checking allow thread-safe client libraries... yes
checking whether to build with Tcl... no
checking whether to build Perl modules... no
checking whether to build Python modules... no
checking whether to build with GSSAPI support... no
checking whether to build with Kerberos 5 support... no
checking whether to build with PAM support... no
checking whether to build with LDAP support... no
checking whether to build with Bonjour support... no
checking whether to build with OpenSSL support... no
checking for grep that handles long lines and -e.../bin/grep
checking for egrep... /bin/grep -E
checking for ld used by GCC... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for ranlib... ranlib
checking for strip... strip
checking whether it is possible to strip libraries... yes
checking for ar... ar
checking for tar... /bin/tar
checking whether ln -s works... yes
checking for gawk... gawk
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for bison... no
configure: WARNING:
*** Without Bison you will not be able to build PostgreSQL from CVSnor
*** change any of the parser definition files. You can obtain Bison from
*** a GNU mirror site.  (If you are using theofficial distribution of
*** PostgreSQL then you do not need to worry about this, becausethe Bison
*** output is pre-generated.)
checking for flex... no
configure: WARNING:
*** Without Flex you will not be able to build PostgreSQL from CVSnor
*** change any of the scanner definition files. You can obtain Flex from
*** a GNU mirror site.  (If you are using theofficial distribution of
*** PostgreSQL then you do not need to worry about this because theFlex
*** output is pre-generated.)
checking for perl... /usr/bin/perl
configure: using perl 5.8.8
checking for main in -lm... yes
checking for library containing setproctitle... no
checking for library containing dlopen... -ldl
checking for library containing socket... none required
checking for library containing shl_load... no
checking for library containing getopt_long... nonerequired
checking for library containing crypt... -lcrypt
checking for library containing fdatasync... nonerequired
checking for library containing gethostbyname_r... nonerequired
checking for library containing shmget... none required
checking for -lreadline... no
checking for -ledit... no
configure: error: readline library notfound
If you have readline already installed, see config.log for detailson the
failure.  It is possible the compiler isnt lookingin the proper directory.
Use --without-readline to disable readlinesupport.

    根据提示,应该是没有安装 readline包。

3 检查系统是否安装 readline 包
[root@HK81-107postgresql-9.0.0]# rpm -qa | grep readline
readline-5.1-3.el5

   说明系统已经安装了 readline包。

4 通过 yum 搜索相关的readline 包
[root@HK81-107postgresql-9.0.0]# yum search readline
lftp.i386 : A sophisticated file transfer program
lftp.i386 : A sophisticated file transfer program
php-readline.i386 : Standard PHP module provides readline librarysupport
lftp.i386 : A sophisticated file transfer program
readline.i386 : A library for editing typed commandlines.
compat-readline43.i386 : The readline 4.3 library for compatibilitywith older software.
readline-devel.i386 : Files needed to develop programs which usethe readline library.
readline.i386 : A library for editing typed command lines.

 根据提示,有一个包引起了我的注意 "readline-devel",猜想可能与这个包有关。
 
5 安装 readline-devel 包
[root@HK81-107postgresql-9.0.0]# yum -y install -y readline-devel
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package readline-devel.i386 0:5.1-3.el5 set tobe updated
--> Processing Dependency: libtermcap-devel forpackage: readline-devel
--> Running transaction check
---> Package libtermcap-devel.i386 0:2.0.8-46.1 setto be updated
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================
 Package                Arch      Version         Repository       Size 
=============================================================================
Installing:
 readline-devel         i386      5.1-3.el5       base             146 k
Installing for dependencies:
 libtermcap-devel       i386      2.0.8-46.1      base              56 k

Transaction Summary
=============================================================================
Install     2Package(s)         
Update      0Package(s)         
Remove      0Package(s)        

Total download size: 201 k
Downloading Packages:
(1/2): libtermcap-devel-2 100%|=========================|  56kB   00:00     
(2/2): readline-devel-5.1 100% |=========================| 146kB   00:00     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing:libtermcap-devel            ######################### [1/2] 
  Installing:readline-devel              ######################### [2/2]

Installed: readline-devel.i386 0:5.1-3.el5
Dependency Installed: libtermcap-devel.i386 0:2.0.8-46.1
Complete!

6 再次执行 configure 成功。

7 关于 readline 的解释,来自官网
--without-readline
Prevents use of the Readline library (and libedit as well). Thisoption disables command-line
editing and  history in psql, so it is notrecommended.

   说明: 根据步骤2 执行 configure时报错提示,可以加上 "--without-readline" 从而避开这个ERROR,
但Postgresql官方不推荐这么做,所以还是安装吧。


--------------------------------------------------------------------------------


4. Ubuntu 10.04的apt里带的pgAdmin是1.10,只能连接pg8.4及以下,但是我要连一个服务器是9.1的,只好装个高版本。结果编译源码安装碰到些问题,google了英文资料也不多,自己试了几下解决的。记录一下:

OS: Ubuntu 10.04 LTS
pgAdmin: 1.14 source code

Install:

./configure
make
make install

Trouble shooting:

1. configure: error: Could not find your PostgreSQL installation. You might need to use the --with-pgsql=DIR configure option

apt-get install libpg-dev

2. configure: error: Could not find your wxWidgets installation. You might need to use the --with-wx=DIR configure option

apt-get install wx-common libwxgtk2.8-dev

3. configure: error: Could not find your libxml2 installation. You might need to use the --with-libxml2=DIR configure option

apt-get install libxml2-dev

4. configure: error: Could not find your libxslt installation. You might need to use the --with-libxslt=DIR configure option

apt-get install libxslt1-dev

5. ./db/keywords.c:33:27: error: parser/kwlist.h:...

apt-get install postgresql-server-dev-8.4



--------------------------------------------------------------------------------


解决/usr/bin/ld:cannot find -lxxx 问题
(2010-10-2116:55:44)
解决/usr/bin/ld: <wbr>cannot <wbr>find <wbr>-lxxx转载
标签:
杂谈
    分类: linux
问题:
在linux环境编译应用程式或lib的sourcecode时常常会出现如下的错误讯息:

        /usr/bin/ld: cannot find -lxxx


这些讯息会随着编译不同类型的source code 而有不同的结果出来如:

        /usr/bin/ld: cannot find -lc
        /usr/bin/ld: cannot find -lltdl
        /usr/bin/ld: cannot find -lXtst


其中xxx即表示函式库文件名称,如上例的:libc.so、libltdl.so、libXtst.so。
其命名规则是:lib+库名(即xxx)+.so。


会发生这样的原因有以下三种情形:

    1 系统没有安装相对应的lib
    2 相对应的lib版本不对
    3 lib(.so档)的symbolic link不正确,没有连结到正确的函式库文件(.so)


对于上述三种原因有一篇文章写的很棒可参考这一篇文章的第4点:
gcc命令祥解


解决方法:
(1)先判断在/usr/lib 下的相对应的函式库文件(.so) 的symbolic link是否正确
若不正确改成正确的连结目标即可解决问题。

(2)若不是symbolic link的问题引起,而是系统缺少相对应的lib安装lib即可解决。

(3)如何安装缺少的lib:
以上面三个错误讯息为例:

    错误1缺少libc的LIB
    错误2缺少libltdl的LIB
    错误3缺少libXtst的LIB 

 

  以Ubuntu为例:
  先搜寻相对应的LIB再进行安装的作业如:

      apt-cache search libc-dev
    apt-cache search libltdl-dev
    apt-cache search libXtst-dev


实例:
在进行输入法gcin的Source Code的编译时出现以下的错误讯息:

    /usr/bin/ld: cannot find -lXtst


经检查后发现是:
lib(.so档)的symbolic link 不正确

解决方法如下:

    cd /usr/lib
    ln -s libXtst.so.6 libXtst.so


如果在/usr/lib的目录下找不到libXtst.so档,那么就表示系统没有安装libXtst的函式库。
解法如下:
apt-get install libxtst-dev


--------------------------------------------------------------------------------


要让网上别的机子都可以访问则要修改以下东西

$vi /home/postgre/data/pg_hba.conf

在底下加入
local       all                                           trust     
#允许通过本地的所有机子
host        all         0.0.0.0       0.0.0.0             trust     
#比如说允许网内192.168.0.96的机子
host        all         192.168.1.0   255.255.255.255     trust                    
host        all         192.168.1.96  255.255.255.255     trust)


$vi /home/postgre/data/postgresql.conf

#tcpip_socket = false      修改成 tcpip_socket = true

$ pg_ctl start -D /usr/local/pgsql/9.1/data          #启动数据库

$ pg_ctl restart  -D /usr/local/pgsql/9.1/data      #重启数据库

$ pg_ctl stop  -D /usr/local/pgsql/9.1/data         #关闭数据库

这样,postgresql就算是安装完毕了,现在我们可以来检验一下;

打开shell输入:

# su - postgre

$ initdb

$ postmaster -i -D ~/data &

$ psql mydb

如果进入数据库,那就是OK了,在这期间比较容易出现问题的是第二步提示你已经存在,这是没有问题的;
但是在执行postmaster -i -D ~/data &,如果有Hint出现,可能是因为上一次打开数据库时没有关,
(关闭shell或是关机是不能将数据库关闭的)因此现输入命令:

$ pg_ctl stop          

然后再执行: $ postmaster -i -D ~/data &

应该就可以了.

退出数据库使用:    \q

=================================================

                         附:解释说明

访问认证配置主要涉及到两个主要的配置文件:postgresql.conf 和 pg_hba.conf。

postgresql.conf 

unix_socket_group: 设置 Unix 域套接字的组所有人,
(套接字的所有权用户总是启动 postmaster 的用户)与 UNIX_SOCKET_PERMISSIONS 选项
一起使用可以给这种套接字类型增加额外的访问控制机制,缺省时是一个空字串,
也就是使用当前用户的缺省的组, 这个选项只能在服务器启动时设置。

unix_socket_permissions:给 Unix 域套接字设置访问权限,
Unix 域套接字使用通常的 Unix 文件系统权限集。可选的值可以是一个 chmod 和 
umask 系统调用可以接受的数字模式。(要使用客户化的八进制格式,该数字必须以 0 (零)开头)


缺省权限是 0777,意即任何人都可以联接,合理的选则可能是0770 
(只有用户和组, 参阅UNIX_SOCKET_GROUP)和 0700 (只有用户)。
(请注意对于 Unix 套接字而言,实际上只有写权限有意义,
而且也没有办法设置或者取消读或执行权限)

这个选项只能在服务器启动时设置。

pg_hba.conf

是设置访问认证的主要文件,格式为每条记录一行,每行指定一条访问认证。
设定一条访问认证包含了7个部分:

连接方式(type)、

数据库(database)、

用户名(user)、

ip地址(ip-address)、

子网掩码(ip-mask)、

认证方法(authentication method)、

认证配置(authentication-option),以下是这7个部分的详细说明:

连接方式(type):连接方式共有三种:local、host、hostssl

local

这条记录匹配通过 Unix 域套接字进行的联接企图, 没有这种类型的记录,
就不允许 Unix 域套接字的联接。

host

这条记录匹配通过 TCP/IP 网络进行的联接尝试,请注意,除非服务器是 带着 -i 选项或者
打开了 postgresql.conf 里面的 tcpip_socket 配置参数集启动的,
否则 TCP/IP 联接是被禁止掉的。

hostssl

这条记录匹配通过在 TCP/IP 上进行的 SSL 联接企图,
host 记录可以匹配 SSL 和非 SSL 的联接企图, 
但 hostssl 记录需要 SSL 联接。

数据库(database):声明记录所匹配的数据库。值 all 表明该记录匹配所有数据库,
值 sameuser表示如果被请求的数据库和请求的用户同名,则匹配。 
samegroup 表示请求的用户必须是一个与数据库同名的组中的成员。 
在其他情况里,这就是一个特定的 PostgreSQL 的名字。 
我们可以通过用逗号分隔的方法声明多个数据库。 
一个包含数据库名的文件可以通过对该文件前缀 @ 来声明该文件必需和 pg_hba.conf 在同一个目录。

用户名(user):为这条记录声明所匹配的 PostgreSQL 用户,值 all 表明它匹配 于所有用户。
否则,它就是特定 PostgreSQL 用户的名字,多个用户名可以通过用逗号分隔的方法声明,
组名字可以通过用 + 做组名字前缀来声明。
一个包含用户名的文件可以通过在文件名前面前缀 @ 来声明,
该文件必需和 pg_hba.conf 在同一个目录。

ip地址(ip-address)和子网掩码(ip-mask):
这两个字段包含标准的点分十进制表示的 IP地址/掩码值。 
(IP地址只能用数字的方式声明,而不能用域名或者主机名)它们俩放在一起,
声明了这条记录匹配的客户机的 IP 地址。 准确的逻辑是: 
(actual-IP- address xor IP-address-field) and IP-mask-field

对于要匹配的记录必需为零。如果连接方式是host或者hostssl的话,这两项必须指定,否则可以不填。

认证方法(authentication method):

trust

无条件地允许联接,这个方法允许任何可以与PostgreSQL 数据库联接的用户以他们期望的任意 
PostgreSQL 数据库用户身份进行联接,而不需要口令。 

reject

联接无条件拒绝,常用于从一个组中"过滤"某些主机。

md5

要求客户端提供一个 MD5 加密的口令进行认证,
这个方法是允许加密口令存储在pg_shadow里的唯一的一个方法。

crypt

类似 md5 方法,只是用的是老式的 crypt 加密认证,用于 7.2 以前的客户端,
对于 7.2 以及以后的客户端,我们建议使用 md5。

password

和"md5"一样,但是口令是以明文形式在网络上传递的,我们不应该在不安全的网络上使用这个方式。

krb4

用 Kerberos V4 认证用户,只有在进行 TCP/IP 联接的时候才能用。
(译注:Kerberos, "克尔波洛斯",故希腊神话冥王哈得斯的多头看门狗。
Kerberos 是 MIT 开发出来的基与对称加密算法的认证协议和/或密钥 交换方法,
其特点是需要两个不同用途的服务器,一个用于认证身份, 一个用于通道两端用户的密钥交换。
同时 Kerberos 对网络时间同步 要求比较高,以防止回放攻击,因此通常伴随 NTP 服务。) 

krb5

用 Kerberos V5 认证用户.只有在进行 TCP/IP 联接的时候才能用。
(译注:Kerberos V5 是上面 V4 的改良,主要是不再依赖 DES 算法,同时增加了一些新特性。) 

ident

获取客户的操作系统名(对于 TCP/IP 联接,
用户的身份是通过与运行在客户端上的 ident 服务器联接进行判断的,
对于本地联接,它是从操作系统获取的。) 
然后检查一下,看看用户是否允许以要求的数据库用户进行联接,
方法是参照在 ident 关键字后面声明的映射。


如果你使用了 sameuser 映射,那么假设用户名 是相等的。如果没有声明这个关键字,
则在 $PGDATA/pg_ident.conf 文件中找出映射名。
如果这个文件里包含一条记录标识着ident提供的用户名 和请求的 PostgreSQL 用户名的映射, 
那么联接被接受。

对于本地联接,只有在系统支持Unix域套接字信任证的情况下 才能使用
(目前是 Linux, FreeBSD, NetBSD, 和 BSD/OS)。

pam

使用操作系统提供的可插入的认证模块服务(Pluggable Authentication Modules)(PAM)来认证

1、无论在本地还是通过tcp/ip,任何人都可以不加任何限制的使用任何他想用的身份访问我的数据库

local    all                                  trust

host    all     0.0.0.0    0.0.0.0    trust

2、所有的访问都使用了md5认证方法

local    all                                  md5

host    all      0.0.0.0    0.0.0.0    md5

3、pgsql用户的认证方法必须为trust不要密码,其它的都用md5认证

local    pgsql                                  trust

local    all                                      md5

host    all          0.0.0.0    0.0.0.0    md5

4、在随后的检测中我发现,虽然通过网络得到了保护,但是如果在本地通过Unix域套接字进行连接的话,
任何人都还是可以使用 `psql -U pgsql -d template1`的方式轻松的进入我的数据库,
这样做显而易见不是我想要的结果,现在我需要unix_socket_permissions的协助,
当我把这个项设置为0700以后,就只有套接字的所有人,即系统用户 pgsql可以使用套接字进行连接,
另外如果我的数据库有几个管理员需要最高权限的话,0770也是一个选择,不过暂时只有我一个管理员,
所以我选择了 0700,现在我的pg_hba.conf改变为:

local    pgsql                                    trust

host    all           0.0.0.0    0.0.0.0    md5

结合了unix_socket_permissions以后,现在只有系统用户pgsql可以无任何限制的连接
(当然,伟大的root例外),并且我也不用每次启动的时候都跑到终端前去输入一次密码了,
而其他人只能通过网络连接,即使登录到了本地计算机上,其他用户也只能使用 
`psql -U xx -d template1 -h 127.0.0.1`的方式连接,这种连接是受到密码认证的保护的,
这一切正是我想要的。

##############################################

数据库启动等命令

pg_ctl start [-w] [-s] [-D datadir] [-l filename] [-o options] [-p path]

pg_ctl stop [-W] [-s] [-D datadir] [-m s[mart] | f[ast] | i[mmediate] ]

pg_ctl restart [-w] [-s] [-D datadir] [-m s[mart] | f[ast] | i[mmediate] ] [-o options]

pg_ctl reload [-s] [-D datadir]

pg_ctl status [-D datadir] 


转载于:https://www.cnblogs.com/leonxyzh/archive/2012/09/02/7289183.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值