PostgreSQL/QuickStart/ko

PostgreSQL 빠른 시작 안내서입니다. PostgreSQL을 이머지하고 설정하는 내용을 다룹니다. 이 안내서는 공식 문서와 상호 보완적인 역할을 하지만, 대체 수단은 아닙니다.

PostgreSQL에 대한 약간의 정보
PostgreSQL is a free and open source relational database management system (RDBMS). It supports such things as transactions, schemata and foreign keys, and is often touted to adhere to the SQL standards more strictly and be more secure, by default, than any other database, commercial or otherwise.

Visit the About page on postgresql.org for more information.

이 글은 무엇을 다루는가
This article will guide you through the Gentoo specific steps to install the PostgreSQL RDBMS.

The ebuild covered by this article is.

This article assumes that you will be installing the latest, stable version of PostgreSQL; at the time of this writing, the version was 9.3.5. Adjust the commands in this article as necessary for your specific version.

이빌드 이야기
The PostgreSQL ebuilds in Portage feature slotting based on the major version. This allows you to have two major versions of PostgreSQL operating simultaneously; 9.0-9.4 libraries and servers can be installed and serve at the same time. This is useful in such circumstances where you need to move data from an older database to a new database, or need to have a production and a testing database on the same machine. Also, this prevents a database, corresponding libraries or executables from being overwritten by an incompatible update. That would require migration which is described in this guide.

Additionally, bug and security fixes, which are delivered via minor version updates, can be applied without fear of corrupting the database or the PostgreSQL installation itself; 9.3.4 can be updated to 9.3.5 as they are guaranteed to be compatible and require no more interaction from you than to emerge it and restart the server process neither migration, reconfiguration nor initialization are necessary.

Read the PostgreSQL Versioning Policy for more information.

이 글에서 다루지 않을 내용은 무엇인가
There is quite a bit that will not be covered. The official documentation is somewhere in the neighborhood of 2,000 pages. So, a lot of details will be left out in this quick start guide. Only Gentoo specific issues will be covered and some basic configuration guidelines.

오래된 이빌드
If you have any of the following ebuilds installed, then you have an older, obsolete Gentoo installation of PostgreSQL and should migrate now:, , , and older than 9.0.

The split ebuilds, , and/or have been unified into a single package:. Nothing is required for you to move from the split ebuilds to the unified ebuild other than to emerge the unified ebuild.

This article does cover migrating from the old ebuilds to the new ones.

이머지 시작
You may receive a notice regarding that any of the above packages are blocked by any or all of the following packages:, , or. These packages are not maintained and obsoleted. Refer to the section on migration from the previous ebuilds to the new ones to know how to handle this situation.

Preparing to Initialize the Database Cluster
Once the packages have finished emerging, you may want to edit. There are three lines that effect the defaults of the server and cannot be changed later without deleting the directory that contains the database cluster and reinitializing.

PGDATA defines where to place the configuration files. DATA_DIR defines where to create the database cluster and related files. PG_INITDB_OPTS may contain any extra options you would care to set. The extra options are not required as the reasonable defaults are, ahem, reasonable.

In the following example, PGDATA states that the configuration files are to be located in. DATA_DIR states that the database cluster should be installed to, which is the default. If you decide to stray from the default, bear in mind that it is a very good idea to keep the major version in the path. PG_INITDB_OPTS states that the default locale should be en_US.UTF-8. That is, U.S. English ordering and formatting, and UTF-8 character encoding.

There are six locale options that can be set to override --locale=. The following table lists the six options that, if used, are to be formatted as:.

So, if you would like the default to be English, but you want messages in, say, Swedish, then your PG_INITDB_OPTS would look like so:

A complete list of language and character encodings supported by the server can be found in the documentation, but your system must also support the respective languages and character encodings. Compare the output of  to the encodings in the documentation.

You can change your locale and encoding selections at database creation time. In order to change the locale for a database after you have created it, you must drop the database and start over again.

This will create the database cluster and store all the related server files into PGDATA and DATA_DIR.

Where the Configuration Files are Located
This time the focus is upon the files in the PGDATA directory,, instead with primary focus on the  and  files.

postgresql.conf
This is the main configuration file. The line that you may find of immediate interest is listen_addresses. This variable defines to which addresses PostgreSQL will bind. By default, only localhost and the Unix socket are bound. Changing listen_addresses is not enough to enable remote connections. That will be covered in the next section. The official documentation is fairly easy to understand and is exhaustive on all the settings available. It would behoove you to read that in addition to what is covered here as some things may change.

Of secondary interest is the logging destination. By default, everything is logged to in the DATA_DIR directory. There is an entire subsection of that covers a slew of options for how, what and where to log. The subsection is marked: ERROR REPORTING AND LOGGING.

Other than listen_addresses and the logging options, the rest of the defaults in are reasonable enough to get you going.

pg_hba.conf
The file states who is allowed to connect to the database server and which authentication method must be used to establish the connection. Again, the documentation is quite exhaustive on the settings and what they all mean, but a few things are covered here for clarification.

As has been mentioned before, by default the server is secure. Kind of. There is only one database role that is available for log in by default: postgres. And, the only way to initiate a connection to the database is through the Unix socket, which is owned by the postgres system user and system group, or via localhost. Now for the "kind of" bit: Any user on the system can make a connection to the database through the localhost. Even as the postgres database superuser.

The trust method is what allows any user to log on as any user without a password. It specifies just what it implies: Trust all connections for the given type to the given database from the given database user (but not the system user) from the given location without a password. This is what allows any user on the system to log on as any user through the localhost connection from the get go. This is not as dangerous as it seems, but does pose a serious security risk in most circumstances.

The two methods you will most likely use are: password and md5. The password method only specifies that a password is required to start the connection and the password is sent "in-the-clear". This method is fine when such information will never leave the machine, such as connecting via the Unix socket or localhost. The md5 method is like password, but protects the password by using an md5 hash. This is what you want to use whenever the password is going to traverse a network.

At this point, this author would like to bring your attention to the last two lines, four lines including comments, of the file. PostgreSQL has native support for IPv6 regardless of your desires for such support. Additionally, IPv4 addresses are automatically mapped to IPv6 addresses, i.e., 127.0.0.1 will be mapped to ::FFFF:127.0.0.1 and as "pure" IPv6 ::FFFF:7F00:0001.

There seems to be some misunderstanding, though, as to how host names are mapped to IP addresses. Let us take a look at the file.

From the example above you can see that both an IPv4 and an IPv6 IP address are mapped to localhost. When  refers to this file, it will grab the first match and use that as the address; in this case 127.0.0.1. When PostgreSQL parses this, it will match the IPv6 formatted address as well, e.g. ::ffff:127.0.0.1. If, however, the IPv6 address appears first, then  will map to ::1 alone; ::1 is not the same as ::ffff:127.0.0.1. As such, if you do not have ::1 as a permitted means of access,  will not be able to establish a connection. Furthermore, your kernel needs to support the IPv6 protocol.

So, it is better to specify IP addresses alone to  and in  rather than to rely on  to be ordered properly, and it removes any doubt as to which IP addresses are allowed or to which server you will connect.

시작합시다!
Now start PostgreSQL and set the password for the database superuser postgres.

Change 'trust' to 'password' for the 'host' (not the 'local', Unix domain socket) connections.

이제 데이터베이스를 시작하십시오:

서버의 연결을 열고 암호를 설정하십시오:

Change 'trust' to 'password' for the local connection:

Now have the database reload the configuration:

Finally, once everything works as it should, have PostgreSQL start at boot:

At this point you are ready to continue on with the official PostgreSQL Tutorial. The tutorial will guide you through creating roles, databases, schemata and all that fun and useful stuff.

이전 작업이 필요할 때
There are only two reasons you would need to perform a migration: When moving from one major version to another, e.g., from PostgreSQL 8.4.7 to 9.0.3, but not from 9.0.2 to 9.0.3; or when switching from the deprecated floating-point timestamp format to the new 64-bit integer timestamp format.

9.0 이후 버전 이전 작업
When upgrading from a previous version of the recent ebuilds, which is any version after 8.4, follow the beginning of this guide before proceeding with this migration.

pg_upgrade, a new utility that comes along with 9.0 and later, simplifies the migration process rather drastically.

However, there are two caveats with using. Firstly, it does not support configuration files being in a different directory than where the data is stored. This can be resolved by using symbolic links. Lastly, you can only use it to migrate from a database from 8.3 or newer. If you have an older database you will need to follow the instructions to migrate from pre-9.0 deployments.

First ensure that the new database cluster is initialized (as described above). Then stop the servers you're going to migrate from and to:

Check available versions, then select yours:

Change the method of database user 'postgres' to trust on local connections on all databases:

You may need to change the permissions of before you perform the next step.

Perform the tasks  tells you to do, if any.

그리고 이제 끝낼 차례입니다:

9.0 이전 버전 이전작업: 새 이빌드 활용
Because the new ebuilds feature a more advanced slotting method than the previous ones, the downtime is quite minimal, most likely minutes rather than hours.

In the following examples, it is assumed that you are using the default locations and port settings, and that you are migrating from 8.3 to 8.4. Adjust accordingly if you have deviated from the default.

If you have not already done so, follow the installation instructions before starting the migration. Such a compile may hamper performance on the database server but it can keep going.

A couple of files need to be tweaked before beginning the migration. Edit PGPORT in the configuration file to 6543. (Any port number other than what your old installation is bound to will do.)

Next, edit so that only the database superuser postgres can access the database cluster via the Unix socket.

The following should be safe. Read the documentation to be sure.

Don't forget to copy over any other configuration files that you may need.

Begin piping the data from the old cluster to the new cluster.

PGPORT를 5432로 되돌리십시오.

Allow users access once more.

Hopefully everything went according to plan and you have a successfully updated server that contains precisely the same data, bit for bit, as the old server.

9.0 이전 버전 이전작업: 오래된 이빌드 활용
You will need to schedule some downtime for your server. The old ebuilds cannot be installed at the same time as the new ebuilds. As such, assume that the server will have to be down for a few hours. Maybe for the weekend, even.

Before starting, you will need to deny access to the server, so that no changes are made. You may also want to backup your and  and any other configuration file that you deem important.

Follow the steps detailed in this article for installing and configuring the server.

You may break some packages that were built against those packages, but once you have installed you can run   to reemerge any packages that may have been broken.

pgAdmin III
pgAdmin III 는 PostgreSQL을 관리하는 그래픽 인터페이스 유틸리티입니다.

서버에 편성 기능이 빠져 있음
이 문제는 어떤 버전을 사용하느냐에 따라 해결 방법이 다르지만 쉽습니다. 답을 찾는게 어려울 뿐입니다. 가져와야 할 필요한 파일은 저장소 드라이브에 이미 있는 파일입니다. 이 문제를 해결하려면, 보유하고 있는 버전에 따라 다음 명령 중 하나를 실행하시면 됩니다.

PostgreSQL 9.0 이전 버전:

PostgreSQL 9.1 이후 버전:

과 에 설정 파일 빠짐
디렉터리에 설정 파일을 이동해볼 수 있는데, 다음에서 x 대신 postgresql 버전 번호를 넣으시면 됩니다:

파일이 빠져있다면 초기화해야합니다.

우선 postgres 사용자로 전환하십시오:

postgres 사용자로 명령을 실행하여 데이터 디렉터리를 지정하십시오:

이 명령은 설정 파일을 만들며 이 섹션의 첫 명령에서 보신바와 같이 에 복사합니다.

"ERROR: timezone directory stack overflow" 또는 "FATAL: too many private dirs demanded" 오류 발생
심볼릭 링크 루프 때문에 일어나는 문제입니다. 문제를 해결하려면 다음 명령을 입력하십시오:

시간대 정보를 업데이트 하면 심볼릭 링크를 다시 만드므로 심볼릭 링크를 다시 제거해야합니다.

Systemd
시작시 서비스를 시작하도록 강제하려면:

서비스를 즉시 시작하려면:

디렉터리가 올바른 위치에 있는지 확인하라는 오류가 나타나는 경우가 있습니다. 디렉터리가 없다면 다음 명령으로 만드십시오:

설정 파일 권한을 확인하십시오: