Received: from robin.mail.pas.earthlink.net (robin.mail.pas.earthlink.net [207.217.120.65]) by postgresql.org (8.11.3/8.11.4) with ESMTP id f8J293d63856 for ; Tue, 18 Sep 2001 22:09:03 -0400 (EDT) (envelope-from nickf@ontko.com) Received: from nick (1Cust222.tnt1.richmond.in.da.uu.net [63.27.103.222]) by robin.mail.pas.earthlink.net (8.11.5/8.9.3) with SMTP id f8J28nH23311; Tue, 18 Sep 2001 19:08:49 -0700 (PDT) Reply-To: From: "Nick Fankhauser" To: "Sven Riedel" , Subject: Re: Problems setting up DB at a different location Date: Tue, 18 Sep 2001 21:07:35 -0500 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0006_01C14085.F0765740" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 X-Archive-Number: 200109/94 X-Sequence-Number: 2195 This is a multi-part message in MIME format. ------=_NextPart_000_0006_01C14085.F0765740 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Sven- I am attaching an html file from our internal company documentation that may help. We are running PostgreSQL 7.1.3 on Debian. The section in the html file marked "Some general concepts and experiences we've had:" includes a description of how we placed data in a separate area. (Most of the links in this doc won't work because they refer to files that live behind our firewall.) One problem that I had was forgetting to use the "-" when doing "su - postgres". The "-" ensures that you pick up any environment variables defined in the postgres user's .profile I hope this helps. I can offer further assistance if it does not. -Nick --------------------------------------------------------------------- Nick Fankhauser nickf@doxpop.com Phone 1.765.965.7363 Fax 1.765.962.9788 doxpop - Court records at your fingertips - http://www.doxpop.com/ ------=_NextPart_000_0006_01C14085.F0765740 Content-Type: text/html; name="pgsql_local.html" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="pgsql_local.html" PostgreSQL Notes and Links

PostgreSQL notes and links



Local Notes

  • We have made the following changes in /etc/postgresql/postgre= sql.conf:

    • tcpip_socket =3D 1 (This allows us to connect via tcp/ip which is required for JDBC, and also useful for separating our database server from our web server. -see pg_hba below for more on this.)
    • shared_buffers =3D 4096 (An increase to allow more cachi= ng - note that we had to increase SHMALL & SHMMAX for the Linux OS to handle this. These should minimally be set to (8192 * buffers)+512. To set SHMALL & SHMMAX in Debian (to 128K in this example), do this: echo 134217728 >/proc/sys/kernel/shmall ; echo 134217728 >/proc/sys/kernel/shmmax )
    • sort_mem =3D 2048 (This increases the space allocated in RAM for sorts. it is measured in KB, so we have allocated 2MB.)=

  • We have added this line to /etc/postgresql/pg_hba.conf:

    • host all 199.164.165.129 255.255.255.255 trust This line says that for all databases, if a request comes from 199.164.165.129, it should be allowed (trusted). The netmask of 255.255.255.255 could be modified to allow a range of addresses to be trusted. This line must be added to the host (database server) machine if connections are to be allowed from anywhere other than localhost.

Some general concepts and experiences we've ha= d:

There is one postmaster per database cluster. The postmaster uses common system files/tables to maintain all databases in the cluster. There is also a common write-ahead-log directory which serves all databases in the cluster.

The initdb command creates the common system files, and we can specify that they be placed anywhere. In our case, I have left these common files in the default of /var/lib/postgres/data because it makes sense to keep the WAL files & system tables on a different disk from the data itself. The total initial space used by the common files is about 20 MB at the outset, of which 16MB is the first WAL file. initdb *must* be run by the postgres user. [su ; su - postgres ; initdb]

The location of the common files may be specified (assuming an initdb has been previously done for that location) when starting the postmaster. By default, databases in the cluster are created in this location as well, but it is possible to specify a different location for each database in the cluster using the procedure below:

The initlocation command creates the data areas which may then be used by the postmaster. In our case, we have created PGDATA_DEMO (/data/pgdata_demo), and PGDATA_ALPHA (/data/pgdata_alpha). [su - postgres ; initlocation PGDATA_DEMO ; initlocation PGDATA_ALPHA ] We anticipate adding PGDATA_PROD and PGDATA_STAGING later.

Note: The environment variables listed above must be defined and exported in /var/lib/postgres/.profile before starting the postmaster. It makes most sense to define all of these as step one.

The createdb command creates the databases themselves. The postmaster must be running before this happens [/etc/init.d/posgresql start]. We have created databases in the locations noted above. [su ; /etc/init.d/postgresql start ; su - postgres ; createdb demo -D PGDATA_DEMO ; createdb alpha -D PGDATA_ALPHA] note that there are no '$' before the environment variables.

To dump (export) a database, this command works: [pg_dump demo >demo.dump]

To restore (import) a database, this command works: [psql -d alpha -f demo.dump]

The two commands shown above exported the contents of demo & reloaded them in alpha. These are fairly small (41Mb) databases. It took about one minute to dump & restore. The created file is simply an SQL file containing creates, inserts, etc... This means we'll want to compress it before sending to tape.

WAL files are basically the same thing as redo logs in Oracle- they are used to both buffer & record transactions against the database tables, resulting in better IO performance and immediate logging of transactions to ensure consistent recovery results. Each WAL file is 16 Mb, and when the current file is 75% full, a new WAL file is created. We can control the number of WAL files initially created and the space between checkpoints via parameters in /etc/postgres/postgresql.conf. I don't yet know if there is any limit on the number of WAL files or a mechanism for automatic cycling or archiving. I've submitted several questions about this to the pgsql-admin list.

The response I've gotten is that in v7.1.3, only 2-3 WAL files are ever created. I'm a bit suspicious of the 2-3... it seems as if the answer should be exactly one number, so take this information with a grain of salt

Some observed behavior:

After creating the demo data & doing a dump/restore of it into alpha,= we had three WAL files (D,E,F).

After restarting the postmaster, we had two WAL files (E,F).

My conjecture is that un-needed WAL files get cleaned out when a rest= art is done, but perhaps not in the normal course of events.

Doing a vacuum analyze on both databases did not cause a third WAL fi= le to be created- conjecture: vacuum doesn't cause much impact on WAL files= , *or* since I had recently done a vacuum on demo & alpha was created frm a= dump, neither had much to be done.

We currently have plenty of space in /var for WAL files. After I recr= eated the databases using the procedure outlined above, we had recovered a= bout 100 Mb. I'm pretty sure that in my confusion, I did an initdb for our = designated data area and assumed that a createdb would then use the same ar= ea. Since the evidence is all gone, I'm not certain what happened, but rega= rdless, the procedure above places everything where we want it.

Useful links

Note: PDF files are cached locally & hence may become stale ------=_NextPart_000_0006_01C14085.F0765740 Content-Type: text/html; name="pgsql_local.html" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="pgsql_local.html" PostgreSQL Notes and Links

PostgreSQL notes and links



Local Notes

  • We have made the following changes in /etc/postgresql/postgre= sql.conf:

    • tcpip_socket =3D 1 (This allows us to connect via tcp/ip which is required for JDBC, and also useful for separating our database server from our web server. -see pg_hba below for more on this.)
    • shared_buffers =3D 4096 (An increase to allow more cachi= ng - note that we had to increase SHMALL & SHMMAX for the Linux OS to handle this. These should minimally be set to (8192 * buffers)+512. To set SHMALL & SHMMAX in Debian (to 128K in this example), do this: echo 134217728 >/proc/sys/kernel/shmall ; echo 134217728 >/proc/sys/kernel/shmmax )
    • sort_mem =3D 2048 (This increases the space allocated in RAM for sorts. it is measured in KB, so we have allocated 2MB.)=

  • We have added this line to /etc/postgresql/pg_hba.conf:

    • host all xxx.xxx.xxx.xxx 255.255.255.255 trust This line says that for all databases, if a request comes from xxx.xxx.xxx.xxx, it should be allowed (trusted). The netmask of 255.255.255.255 could be modified to allow a range of addresses to be trusted. This line must be added to the host (database server) machine if connections are to be allowed from anywhere other than localhost.

Some general concepts and experiences we've ha= d:

There is one postmaster per database cluster. The postmaster uses common system files/tables to maintain all databases in the cluster. There is also a common write-ahead-log directory which serves all databases in the cluster.

The initdb command creates the common system files, and we can specify that they be placed anywhere. In our case, I have left these common files in the default of /var/lib/postgres/data because it makes sense to keep the WAL files & system tables on a different disk from the data itself. The total initial space used by the common files is about 20 MB at the outset, of which 16MB is the first WAL file. initdb *must* be run by the postgres user. [su ; su - postgres ; initdb]

The location of the common files may be specified (assuming an initdb has been previously done for that location) when starting the postmaster. By default, databases in the cluster are created in this location as well, but it is possible to specify a different location for each database in the cluster using the procedure below:

The initlocation command creates the data areas which may then be used by the postmaster. In our case, we have created PGDATA_DEMO (/data/pgdata_demo), and PGDATA_ALPHA (/data/pgdata_alpha). [su - postgres ; initlocation PGDATA_DEMO ; initlocation PGDATA_ALPHA ] We anticipate adding PGDATA_PROD and PGDATA_STAGING later.

Note: The environment variables listed above must be defined and exported in /var/lib/postgres/.profile before starting the postmaster. It makes most sense to define all of these as step one.

The createdb command creates the databases themselves. The postmaster must be running before this happens [/etc/init.d/posgresql start]. We have created databases in the locations noted above. [su ; /etc/init.d/postgresql start ; su - postgres ; createdb demo -D PGDATA_DEMO ; createdb alpha -D PGDATA_ALPHA] note that there are no '$' before the environment variables.

To dump (export) a database, this command works: [pg_dump demo >demo.dump]

To restore (import) a database, this command works: [psql -d alpha -f demo.dump]

The two commands shown above exported the contents of demo & reloaded them in alpha. These are fairly small (41Mb) databases. It took about one minute to dump & restore. The created file is simply an SQL file containing creates, inserts, etc... This means we'll want to compress it before sending to tape.

WAL files are basically the same thing as redo logs in Oracle- they are used to both buffer & record transactions against the database tables, resulting in better IO performance and immediate logging of transactions to ensure consistent recovery results. Each WAL file is 16 Mb, and when the current file is 75% full, a new WAL file is created. We can control the number of WAL files initially created and the space between checkpoints via parameters in /etc/postgres/postgresql.conf. I don't yet know if there is any limit on the number of WAL files or a mechanism for automatic cycling or archiving. I've submitted several questions about this to the pgsql-admin list.

The response I've gotten is that in v7.1.3, only 2-3 WAL files are ever created. I'm a bit suspicious of the 2-3... it seems as if the answer should be exactly one number, so take this information with a grain of salt

Some observed behavior:

After creating the demo data & doing a dump/restore of it into alpha,= we had three WAL files (D,E,F).

After restarting the postmaster, we had two WAL files (E,F).

My conjecture is that un-needed WAL files get cleaned out when a rest= art is done, but perhaps not in the normal course of events.

Doing a vacuum analyze on both databases did not cause a third WAL fi= le to be created- conjecture: vacuum doesn't cause much impact on WAL files= , *or* since I had recently done a vacuum on demo & alpha was created frm a= dump, neither had much to be done.

We currently have plenty of space in /var for WAL files. After I recr= eated the databases using the procedure outlined above, we had recovered a= bout 100 Mb. I'm pretty sure that in my confusion, I did an initdb for our = designated data area and assumed that a createdb would then use the same ar= ea. Since the evidence is all gone, I'm not certain what happened, but rega= rdless, the procedure above places everything where we want it.

Useful links

Note: PDF files are cached locally & hence may become stale ------=_NextPart_000_0006_01C14085.F0765740--