postgresql初始化

http://www.cnblogs.com/huayumeng/p/3156263.html

postgresql使用文档之一 初始化数据存储区

17.2. 创建一个数据库集群(Database Cluster)

  在你能做任何事情之前,你必须在磁盘上初始化一块存储空间。我们称这为一个数据库集群(database cluster). 一个Database cluster是一批被一个运行着数据库服务的示例所管理的数据库.初始化以后,一个database cluster将会包含一个名为 postgres的数据库,它是一个被一些工具、用户和第三方应用使用的默认数据库。数据库服务器本身不需要 postgres ,但是很多外部的程序会假设它存在。另外一个在每一个cluster初始化时创建的数据库叫做 template1. 就像它的名字所暗示,它会被用来作为一个创建后续数据库所使用的模板;它不应该被实际工作所使用(参考21章获取关于在一个集群中创建新的数据库的信息)

在文件系统术语中,一个database cluster是单个的目录,所有的数据会被存储在这个目录下。我们称这个目录为数据目录(data directory)或数据区域(data area).选择在哪个目录下存储您的数据完全取决于您,没有默认目录,尽管诸如/usr/local/pgsql/data或/var/lib/pgsql/data之类的目录作为数据目录是比较流行的。初始化一个database cluster,使用initdb命令,它是和PostgreSQL一起安装的。您期望的的database cluster文件系统目录使用选项 -D标注,如例:

 $initdb -D /usr/local/pgsql/data

注意在您登录PostgreSQL用户账户之前必须先执行这个命令,这在上一节已经描述过了。(提示:您可以设置环境变量PGDATA来替换-D选项)

可供选择的,您也可以通过pg_ctl程序像下面这样运行 initdb

 $pg_ctl -D /usr/local/pgsql/data initdb

如果您使用pg_ctl启动和停止服务器(查看17.3节)将会更加直观。这样的话在管理数据库服务器示例时pg_ctl将会是唯一的一个命令。

initdb将会尝试创建你指定的一个不存在的目录。很有可能您没有权限创建(如果您尊随我们的建议并创建了一个非特权账户)。在这种情况下,您应该创建这个目录(比如用root权限),然后改变这个目录的拥有者(owner)为PostgreSQL用户。以下示范应该如何做:

root# mkdir /usr/local/pgsql/data
root# chown postgres /usr/local/pgsql/data
root# su postgres
postgres$ initdb -D /usr/local/pgsql/data

如果数据目录已经存在且初始化了的话,initdb将不会运行。

由于数据目录包含了所有存储在数据库里的数据,因此应该有对未授权的访问的安全机制。initdb收回了所有其他用户的访问权限,除了PostgreSQL用户.

然而,尽管这个目录下的内容是安全的,默认的客户授权设置允许任何本地用户连接数据库甚至成为数据库超级用户(管理员)。如果您不信任本地的其他用户,我们建议您使用任意一种initdb的选项-W,--pwprompt或--pwfile来分配给数据库超级用户的密码。并且,指定-A md5或-A password,这样默认的 trust 授权模式不起作用;或者在运行initdb后,第一次启动您的数据库服务器之前修改生成的pg_hda.conf文件。(其他的合理的途径包括使用peer授权或文件系统权限来限制链接。查看19章获取更多信息)

initdb同时为database cluster初始化默认的locale,一般而言,它只是使用本地locale设置并将其应用到初始化的数据库中。为数据库指定一个其他的locale是可能的;更多的信息可以在22.1节找到。默认的应用在特定的database cluster上的排序(sort order)是被initdb设置的,并且如果您创建了使用不同的排序的新的数据库,除非您删除重建它,在template数据库中使用的order是不会改变的。使用其他的locale而不是使用C或POSIX会对性能产生影响。因此在第一次正确的选择选项是很重要的。

initdb同时为database cluster设置默认的字符集和encoding。一般而言应该选择匹配locale设置。更多细节查看22.3节

17.2.1 网络文件系统

很多安装在网络文件系统创建database cluster。有些直接用NFS,或者使用内部使用NFS的NAS来完成。PostgreSQL并非特定于NFS文件系统,意味着它使用NFS的方式和本地连接的驱动(DAS,直接连接的存储器)完全一致。如果客户端和服务端的NFS实现未遵循标准的语意(semantics),这可能会产生可靠性问题(查看http://www.time-travellers.org/shane/papers/NFS_considered_harmful.html).具体而言,延时(异步)写入NFS服务器会产生可靠性问题;如果可以,尽量同步挂载(不用缓存)

 

 

 

http://www.postgresql.org/docs/9.3/static/app-initdb.html

initdb

Name

initdb -- create a new PostgreSQL database cluster

Synopsis

initdb [option...] [--pgdata | -Ddirectory

Description

initdb creates a new PostgreSQL database cluster. A database cluster is a collection of databases that are managed by a single server instance.

Creating a database cluster consists of creating the directories in which the database data will live, generating the shared catalog tables (tables that belong to the whole cluster rather than to any particular database), and creating the template1 and postgres databases. When you later create a new database, everything in the template1 database is copied. (Therefore, anything installed in template1 is automatically copied into each database created later.) The postgres database is a default database meant for use by users, utilities and third party applications.

Although initdb will attempt to create the specified data directory, it might not have permission if the parent directory of the desired data directory is root-owned. To initialize in such a setup, create an empty data directory as root, then use chown to assign ownership of that directory to the database user account, then su to become the database user to run initdb.

initdb must be run as the user that will own the server process, because the server needs to have access to the files and directories that initdb creates. Since the server cannot be run as root, you must not run initdb as root either. (It will in fact refuse to do so.)

initdb initializes the database cluster's default locale and character set encoding. The character set encoding, collation order (LC_COLLATE) and character set classes (LC_CTYPE, e.g. upper, lower, digit) can be set separately for a database when it is created. initdb determines those settings for the template1 database, which will serve as the default for all other databases.

To alter the default collation order or character set classes, use the --lc-collate and --lc-ctype options. Collation orders other than C or POSIX also have a performance penalty. For these reasons it is important to choose the right locale when running initdb.

The remaining locale categories can be changed later when the server is started. You can also use --locale to set the default for all locale categories, including collation order and character set classes. All server locale values (lc_*) can be displayed via SHOW ALL. More details can be found in Section 22.1.

To alter the default encoding, use the --encoding. More details can be found in Section 22.3.

Options

-A authmethod
--auth=authmethod

This option specifies the authentication method for local users used in pg_hba.conf (host and local lines). Do not use trust unless you trust all local users on your system. trust is the default for ease of installation.

--auth-host=authmethod

This option specifies the authentication method for local users via TCP/IP connections used in pg_hba.conf (host lines).

--auth-local=authmethod

This option specifies the authentication method for local users via Unix-domain socket connections used in pg_hba.conf (local lines).

-D directory
--pgdata=directory

This option specifies the directory where the database cluster should be stored. This is the only information required by initdb, but you can avoid writing it by setting the PGDATA environment variable, which can be convenient since the database server (postgres) can find the database directory later by the same variable.

-E encoding
--encoding=encoding

Selects the encoding of the template database. This will also be the default encoding of any database you create later, unless you override it there. The default is derived from the locale, or SQL_ASCII if that does not work. The character sets supported by the PostgreSQL server are described in Section 22.3.1.

-k
--data-checksums

Use checksums on data pages to help detect corruption by the I/O system that would otherwise be silent. Enabling checksums may incur a noticeable performance penalty. This option can only be set during initialization, and cannot be changed later. If set, checksums are calculated for all objects, in all databases.

--locale=locale

Sets the default locale for the database cluster. If this option is not specified, the locale is inherited from the environment that initdb runs in. Locale support is described in Section 22.1.

--lc-collate=locale
--lc-ctype=locale
--lc-messages=locale
--lc-monetary=locale
--lc-numeric=locale
--lc-time=locale

Like --locale, but only sets the locale in the specified category.

--no-locale

Equivalent to --locale=C.

-N
--nosync

By default, initdb will wait for all files to be written safely to disk. This option causes initdb to return without waiting, which is faster, but means that a subsequent operating system crash can leave the data directory corrupt. Generally, this option is useful for testing, but should not be used when creating a production installation.

--pwfile=filename

Makes initdb read the database superuser's password from a file. The first line of the file is taken as the password.

-S
--sync-only

Safely write all database files to disk and exit. This does not perform any of the normal initdb operations.

-T CFG
--text-search-config=CFG

Sets the default text search configuration. See default_text_search_config for further information.

-U username
--username=username

Selects the user name of the database superuser. This defaults to the name of the effective user running initdb. It is really not important what the superuser's name is, but one might choose to keep the customary name postgres, even if the operating system user's name is different.

-W
--pwprompt

Makes initdb prompt for a password to give the database superuser. If you don't plan on using password authentication, this is not important. Otherwise you won't be able to use password authentication until you have a password set up.

-X directory
--xlogdir=directory

This option specifies the directory where the transaction log should be stored.

Other, less commonly used, options are also available:

-d
--debug

Print debugging output from the bootstrap backend and a few other messages of lesser interest for the general public. The bootstrap backend is the program initdb uses to create the catalog tables. This option generates a tremendous amount of extremely boring output.

-L directory

Specifies where initdb should find its input files to initialize the database cluster. This is normally not necessary. You will be told if you need to specify their location explicitly.

-n
--noclean

By default, when initdb determines that an error prevented it from completely creating the database cluster, it removes any files it might have created before discovering that it cannot finish the job. This option inhibits tidying-up and is thus useful for debugging.

Other options:

-V
--version

Print the initdb version and exit.

-?
--help

Show help about initdb command line arguments, and exit.

Environment

PGDATA

Specifies the directory where the database cluster is to be stored; can be overridden using the -D option.

This utility, like most other PostgreSQL utilities, also uses the environment variables supported by libpq (see Section 31.14).

Notes

initdb can also be invoked via pg_ctl initdb.

See Also

pg_ctlpostgres
 
 
 
 
http://manpages.ubuntu.com/manpages/lucid/zh_CN/man1/initdb.1.html

NAME

       initdb - 创建一个新的 PostgreSQL数据库集群

SYNOPSIS

       initdb [ option... ]  --pgdata  | -D directory

DESCRIPTION ����述
       initdb           创建一个新的          PostgreSQL          数据库集群。
       一个数据库集群是由单个服务器实例管理的数据库集合。

        创建数据库系统包括创建数据库数据的宿主目录,
       生成共享的系统表(不属于任何特定数据库的表)和创建            template1
       数据库。当你以后再创建一个新数据库时,                        template1
       数据库里所有内容都会拷贝过来。 它包括填充了象内建类型这样的系统表。

       initdb                       初始化该数据库集群的缺省区域和字符集编码。
       有些区域范畴对该集群而言是全生命期固定的,因此在运行             initdb
       的时候选取正确的是非常重要的。
       其它区域范畴可以在服务器启动之后的时间里改变。                   initdb
       将把那些区域设置写到   postgresql.conf   配置文件,这样它们就是缺省的,
       但是我们可以通过编寄切┪募来修改它们。 要设置 initdb  使用的区域,参阅
       --locale  选项的描述。字符集编码可以在数据库创建的时候独立设置。 initdb
       决定    template1    数据库的编码,而该编码将成为所有其它数据库的缺省。
       要修改缺省编码,我们可以使用 --encoding 选项。

       initdb                     必须以运行数据库服务器进程的用户身份运行它。
       因为服务器需要能够访问 initdb  创建的文件和目录。 因为服务器不能以 root
       身份运行,所以你也不能以  root  身份运行  initdb。(实际上它拒绝以 root
       身份运行。)

        尽管initdb会尝试创建相应的数据目录,                              但-
       常会发生它没有权限做这些事情的情况。因为所需要的目录的父目录通常是 root
       所有的目录。 要为此安排做一个设置,用 root 创建一个空数据目录,  然后用
       chown        把该目录的所有权交给数据库用户帐号,        然后        su
       成数据库用户,最后以数据库用户身份运行 initdb。

OPTIONS����项
       -D directory

       --pgdata=directory
               这个选项声明数据库集群应该存放在哪个目录。
              这是initdb需要的唯一信息,但是你可以通过设置              PGDATA
              环境变量来避免键入,
              这样做可能方便一些,因为稍后数据库服务器(postmaster)可以通过同一个变量找到数据库目录。

       -E encoding

       --encoding=encoding
               选择模板数据库的编码方式。这将是你以后创建的数据库的缺省编码方式,
              除非你创建数据库时覆盖了它。 缺省是 SQL_ASCII。

       --locale=locale
               为数据库集群设置缺省的区域。如果没有声明这个选项,那么区域 是从
              initdb 运行的环境中继承过来的。

       --lc-collate=locale

       --lc-ctype=locale

       --lc-messages=locale

       --lc-monetary=locale

       --lc-numeric=locale

       --lc-time=locale
               类似 --locale,但是只设置特殊范畴的区域。

       -U username

       --username=username
               选择数据库超级用户的用户名。         缺省是运行          initdb
              的用户的有效用户。                超级用户的名字是什么并不重要,
              但是我们可以选择习惯的名字
              postgres,即使操作系统的用户名字不一样也无所谓。

       -W

       --pwprompt
               令             initdb            提示输入数据库超级用户的口令。
              如果你不准备使用口令认证,这个东西并不重要。
              否则你将不能使用口令认证直到你设置了口令。

        其他不常用的参数还有:

       -d

       --debug
               从初始化后端打印调试输出以及一些其它的一些普通用户不太感兴趣的信息。
              初始化后端是            initdb            用于创建系统表的程序。
              这个选项生成大量非常烦人的输出。

       -L directory
               告诉       initdb        到哪里找初始化数据库所需要的输入文件。
              通常是不必要的。如果需要你明确声明的话,程序会提示你输入。

       -n

       --noclean
               缺省时,当initdb  发现一些错误妨八瓿纱唇ㄊ菘饧旱墓ぷ魇保
              它将在检测到不能结束工作之前将其创建的所有文件删除。
              这个选项禁止任何清理动作,因而对调试很有用。

ENVIRONMENT����境
       PGDATA  声明数据库集群存储的目录;可以用 -D 选项覆盖。



http://huangyandong.blog.51cto.com/1396940/742902
initdb

名称:初始化一个PostgreSQL数据库簇

语法:

    initdb [OPTION] [DATADIR]

选项:

    -A,--auth=METHOD:指定本地连接的认证方法

    [-D,--pgdata=]DATADIR:指定数据库簇的原始目录(必须为空)

    -E,--encoding=ENCODING:指定数据库的默认编码

    --locale=LOCALE:设置数据库的locale

    --no-locale:等价--locale=C

    --pwfile=FILE:从指定的文件FILE中读取超级用户的密码

    -T,--text-search-config=CFG:指定默认的配置

    -U,--username=Username:指定用户名

    -W,--pwprompt:强制提示密码输入

    -X,--xlogdir=XLOGDIR:指定事务日志的目录文件

实例:

    ./initdb -D /usr/local/postgres/data

    
 

本文出自 “黄彦东” 博客,请务必保留此出处http://huangyandong.blog.51cto.com/1396940/742902

 

 

http://stackoverflow.com/questions/11814740/what-is-going-wrong-with-postgresql-initdb-why-is-the-utf-8-encoding-not-gett

I am using PostgreSQL 9.1. Trying to enforce UTF8 encoding as default.

This is what I am doing.

service postgresql initdb -E 'UTF-8' --lc-collate='en_US.UTF-8' --lc-ctype=locale='en_US.UTF-8';

Although the initilization process goes on without any problem,

\l at the psql prompt gives there details.

                        List of databases

Name      |  Owner|Encoding| Collate | Ctype | Access privileges
-----------+----------+----------+---------+-------+-----------------------
postgres | postgres| LATIN1 | en_US | en_US|

Why is the UTF-8 encoding not getting enforced?

shareimprove this question
 

Looks like you are calling initdb through a runlevel script of the OS. This script might not pass on the parameters. You better try executing initdb directly, you will need to perform the following steps starting as root and assuming the OS user account for the database is postgres.

mkdir <your data dir>
chown postgres <your data dir>
su postgres
initdb --pgdata=<your data dir> -E 'UTF-8' --lc-collate='en_US.UTF-8' --lc-ctype='en_US.UTF-8'
shareimprove this answer
 
1  
You are right. Although I couldn't run initdb directly as a superuser. gave an initdb: cannot be run as root Please log in (using, e.g., "su") as the (unprivileged) user that will own the server process. error. After logging in as an unprivileged user I was able to initialize the db with the proper encoding. –  ThinkingMonkey Aug 5 '12 at 8:38 
    
Forgot about it being a bit picky, updated the answer with the full set of commands that might be needed. – Eelke Aug 5 '12 at 8:49
    
Thank you...... –  ThinkingMonkey Aug 5 '12 at 8:52
    
Hello guys! Do you have any idea why I get: initdb: invalid locale name "'en_US.UTF-8'" ? I have also tried without the quotes, but then I get initdb: invalid locale name "en_US.UTF-8". I have downloaded the Postgresql9.4.1 binaries (not the installer) for Windows. Is the locale en_US.UTF-8 not available in the Windows binaries? –  Sorin Postelnicu Mar 16 at 9:51
 
 
 
 
http://postgres-xc.sourceforge.net/docs/1_1/creating-cluster.html

16.2. Creating a Database Cluster

Before you can do anything, you must initialize a database storage area on disk. We call this a database cluster. (SQL uses the term catalog cluster.) A database cluster is a collection of databases that is managed by a single instance of a running database server. After initialization, a database cluster will contain a database named postgres, which is meant as a default database for use by utilities, users and third party applications. The database server itself does not require the postgres database to exist, but many external utility programs assume it exists. Another database created within each cluster during initialization is called template1. As the name suggests, this will be used as a template for subsequently created databases; it should not be used for actual work. (See Chapter 20 for information about creating new databases within a cluster.)

Note: The following description applies only to Postgres-XC

You should initialize database cluster for each Coordinator and Datanode.

In file system terms, a database cluster will be a single directory under which all data will be stored. We call this the data directory or data area. It is completely up to you where you choose to store your data. There is no default, although locations such as /usr/local/pgsql/data or /var/lib/pgsql/data are popular. To initialize a database cluster, use the command initdb, which is installed with Postgres-XC. The desired file system location of your database cluster is indicated by the -D option, for example:

$ initdb -D /usr/local/pgsql/data --nodename foo

Note that you must execute this command while logged into the Postgres-XC user account, which is described in the previous section. You should assign separate data directory to each Coordinator and Datanode if you are configuring them in a same server.

Tip: As an alternative to the -D option, you can set the environment variable PGDATA.

If you configure multiple Coordinator and/or Datanode, you cannot share PGDATA among them and you must specify data directory explicitly.

--nodename is mandatory for all the nodes at initialization

Alternatively, you can run initdb via the pg_ctl program like so:

$ pg_ctl -D /usr/local/pgsql/data -o '--nodename foo' initdb

This may be more intuitive if you are using pg_ctl for starting and stopping the server (see Section 16.3), so that pg_ctl would be the sole command you use for managing the database server instance.

initdb will attempt to create the directory you specify if it does not already exist. It is likely that it will not have the permission to do so (if you followed our advice and created an unprivileged account). In that case you should create the directory yourself (as root) and change the owner to be the Postgres-XC user. Here is how this might be done:

root# mkdir /usr/local/pgsql/data
root# chown postgres /usr/local/pgsql/data
root# su postgres
postgres$ initdb -D /usr/local/pgsql/data --nodename foo

 

initdb will refuse to run if the data directory looks like it has already been initialized.

Because the data directory contains all the data stored in the database, it is essential that it be secured from unauthorized access. initdb therefore revokes access permissions from everyone but the Postgres-XC user.

However, while the directory contents are secure, the default client authentication setup allows any local user to connect to the database and even become the database superuser. If you do not trust other local users, we recommend you use one of initdb's -W--pwprompt or --pwfile options to assign a password to the database superuser. Also, specify -A md5 or -A passwordso that the default trust authentication mode is not used; or modify the generated pg_hba.conf file after running initdb, but before you start the server for the first time. (Other reasonable approaches include using peer authentication or file system permissions to restrict connections. See Chapter 18 for more information.)

initdb also initializes the default locale for the database cluster. Normally, it will just take the locale settings in the environment and apply them to the initialized database. It is possible to specify a different locale for the database; more information about that can be found in Section 21.1. The default sort order used within the particular database cluster is set by initdb, and while you can create new databases using different sort order, the order used in the template databases that initdb creates cannot be changed without dropping and recreating them. There is also a performance impact for using locales other than C or POSIX. Therefore, it is important to make this choice correctly the first time.

initdb also sets the default character set encoding for the database cluster. Normally this should be chosen to match the locale setting. For details see Section 21.3.

16.2.1. Network File Systems

Many installations create database clusters on network file systems. Sometimes this is done directly via NFS, or by using a Network Attached Storage (NAS) device that uses NFSinternally. Postgres-XC does nothing special for NFS file systems, meaning it assumes NFS behaves exactly like locally-connected drives (DAS, Direct Attached Storage). If client and server NFS implementations have non-standard semantics, this can cause reliability problems (see http://www.time-travellers.org/shane/papers/NFS_considered_harmful.html). Specifically, delayed (asynchronous) writes to the NFS server can cause reliability problems; if possible, mount NFS file systems synchronously (without caching) to avoid this. Also, soft-mounting NFS is not recommended. (Storage Area Networks (SAN) use a low-level communication protocol rather than NFS.)

 

 

http://www.ovirt.org/Installing_PostgreSQL_DB

Installing PostgreSQL DB

 

Warning

This page contains obsolete information and has been recommended for deletion!

Installing

Please take into account that installing and starting a database is a system administration task, so all the commands suggested in this page are to be executed with the root user.

Fedora

# yum install -y postgresql-server

Debian

# apt-get install postgresql

Make sure you are using PostgreSQL 8.4.8 or later. Check your version with:

# psql --version

Note: for earlier PostgreSQL versions, a patch is needed.

Running the service

From PostgreSQL 9

Before starting the database for the first time you need to initialize it using the postgresql-setup command with the initdb option:


Fedora

# postgresql-setup initdb

Once it is initialized you can start and stop it with the systemctl command. For example, to start it:

# systemctl start postgresql.service

It is recommended to configure the service so that it is automatically started the next time the machine is rebooted:

# systemctl enable postgresql.service

If the database needs to be recreated from scratch the way to do it is to stop the service, remove the data directory, run the postgresql-setup command again, and start the service:

# systemctl stop postgresql.service
# rm -rf /var/lib/pgsql/data
# postgresql-setup initdb
# systemctl start postgresql.service

Debian

The database is automatically initialized, started and configured to start during boot as part of the installation of the package, no need to perform any additional initialization.

To start, stop or restart it use the /etc/init.d/postgresql script:

# /etc/init.d/postgresql start

For PostgreSQL 8 or earlier (not recommended)

Before starting the database for the first time you need to initialize it running the initdb command with the postgres user:

# su - postgres -c 'initdb -U postgres -D /var/lib/pgsql/data/'

Once it is initialized you can start and stop it with the service command. For example, to start it run the following command:

# service postgresql start

It is recommended to configure the service so that it is automatically started the next time the machine is rebooted:

# chkconfig postgresql on

Connecting to the database

Note that this instructions are mostly the same for all distributions, the main difference is the location of the configuration files. For reference see the PostgreSQL documentation here.

Fedora

Edit the /var/lib/pgsql/data/pg_hba.conf file and set authentication parameters as follows:

local   all         all                               peer
host    all         all         127.0.0.1/32          md5
host    all         all         ::1/128               md5

After that run systemctl restart postgresql.service so that the new settings will take effect.

Debian

Edit the /etc/postgresql/9.1/main/pg_hba.conf file and set authentication parameters as follows:

local   all         all                               peer
host    all         all         127.0.0.1/32          md5
host    all         all         ::1/128               md5

After that run /etc/init.d/postgresql restart so that the new settings will take effect.

Connecting from other hosts (optional)

If you want to be able to connect to PostgreSQL from other hosts (i.e. not from localhost only) you will need to change the listen_addresses parameter, as the default is to accept local connections only.

Fedora

Edit the /var/lib/pgsql/data/postgresql.conf file:

listen_addresses = '0.0.0.0'

And you will need also to allow access from external hosts in the /var/lib/pgsql/data/pg_hba.conf file:

host    all         all         10.35.0.0/16          trust

The 10.35.0.0/16 network address and mask are just an example, make sure you replace it with what you want to give permissions to.

After all these changes restart the PostgreSQL service:

# systemctl restart postgresql.service

Debian

Same as in Fedora, but the location of the files are /etc/postgresql/9.1/main/postgresql.conf and /etc/postgresql/9.1/main/pg_hba.conf.

After all these changes restart the PostgreSQL service:

# /etc/init.d/postgresql restart



http://www.linuxfly.org/post/88/
项目需要部署Open Country,其要求使用Postgresql 7.0或8.0版本。系统为红旗DC 5.0 for x86,默认安装有Postgresql 8.0。
 启动时候出现下面的故障提示:
引用
# service postgresql start
正在初始化数据库:                                         [失败]
启动 postgresql 服务:                                     [失败]

 查看/etc/init.d/postgresql文件,尝试手动初始化数据库:
引用
[root@localhost ~]# su - postgres
-bash-3.00$ initdb
属于此数据库系统的文件宿主为用户 "postgres".
此用户也必须为服务器进程的宿主.
数据库簇将带有 locale zh_CN.GB18030 初始化.
initdb: 无法为 locale "zh_CN.GB18030" 找到合适的编码
带 -E 选项重新运行 initdb.
请用 "initdb --help" 获取更多的信息.

 故障应该和系统的locale设定有关,使用下面的命令解决:
引用
-bash-3.00$ initdb --no-locale
属于此数据库系统的文件宿主为用户 "postgres".
此用户也必须为服务器进程的宿主.
数据库簇将带有 locale C 初始化.

修复已存在目录 /var/lib/pgsql/data 的权限 ... 成功
创建目录 /var/lib/pgsql/data/global ... 成功
创建目录 /var/lib/pgsql/data/pg_xlog ... 成功
创建目录 /var/lib/pgsql/data/pg_xlog/archive_status ... 成功
创建目录 /var/lib/pgsql/data/pg_clog ... 成功
创建目录 /var/lib/pgsql/data/pg_subtrans ... 成功
创建目录 /var/lib/pgsql/data/base ... 成功
创建目录 /var/lib/pgsql/data/base/1 ... 成功
创建目录 /var/lib/pgsql/data/pg_tblspc ... 成功
选择默认最大联接数 (max_connections) ... 100
选择默认共享缓冲区大小 (shared_buffers) ... 1000
创建配置文件 ... 成功
在 /var/lib/pgsql/data/base/1 中创建 template1 数据库 ... 成功
初始化 pg_shadow ... 成功
启动不限制系统表行大小 ... 成功
初始化 pg_depend ... 成功
创建系统视图 ... 成功
加载 pg_description ... 成功
创建字符集转换 ... 成功
对内建对象设置权限 ... 成功
创建信息模式 ... 成功
清理数据库 template1 ... 成功
拷贝 template1 到 template0 ... 成功

警告: 为本地连接启动了 "trust" 认证.
你可以通过编辑 pg_hba.conf 更改或你下
次运行 initdb 时使用 -A 选项.

成功. 您现在可以用下面的命令运行数据库服务器:

   postmaster -D /var/lib/pgsql/data
或者
   pg_ctl -D /var/lib/pgsql/data -l logfile start

 退出到root用户,重新运行服务:
引用
[root@localhost ~]# service postgresql start
启动 postgresql 服务:                                     [  确定  ]

 一切正常。问题解决!




 

 

 

 

 

 

posted @   陳聽溪  阅读(27449)  评论(2编辑  收藏  举报
点击右上角即可分享
微信分享提示