From: Nick Fankhauser <nickf@ontko.com>
To: Sven Riedel <sven.riedel@tu-clausthal.de>
To: pgsql-admin@postgresql.org
Subject: Re: Problems setting up DB at a different location
Date: Tue, 18 Sep 2001 21:07:35 -0500
Message-ID: <NEBBLAAHGLEEPCGOBHDGIEPCDKAA.nickf@ontko.com> (raw)
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/Attachments:pgsql_local.html (text/html, 8.8K) download
<html>
<head>
<title>PostgreSQL Notes and Links</title>
</head>
<body>
<h1>PostgreSQL notes and links</h1>
<ul>
<li><a href = "#local">Local Notes</a>
<li><a href = "#concepts">Concepts & Conjecture</a>
<li><a href = "#links">Links to other documention</a>
</ul>
<br>
<br>
<a name = local><h2>Local Notes</h2></a>
<ul>
<li><h3>We have made the following changes in /etc/postgresql/postgresql.conf:</h3>
<ul>
<li><b>tcpip_socket = 1</b> (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.)
<li><b>shared_buffers = 4096</b> (An increase to allow more caching -
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 )
<li><b>sort_mem = 2048</b> (This increases the space allocated in
RAM for sorts. it is measured in KB, so we have allocated 2MB.)<br><br>
</ul>
<li><h3>We have added this line to /etc/postgresql/pg_hba.conf:</h3>
<ul>
<li><b>host all 199.164.165.129 255.255.255.255 trust</b> This
line says that for <b>all</b> databases, if a request comes
from <b>199.164.165.129</b>, it should be allowed
(<b>trust</b>ed). The netmask of <b>255.255.255.255</b> 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.
</ul>
</ul>
<a name = concepts><h2>Some general concepts and experiences we've had:</h2></a>
<p>
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.
</p>
<p>
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]
</p>
<p>
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:
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
To dump (export) a database, this command works:
[pg_dump demo >demo.dump]
</p>
<p>
To restore (import) a database, this command works:
[psql -d alpha -f demo.dump]
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
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
</p>
<p>
Some observed behavior:
</p>
<p>
After creating the demo data & doing a dump/restore of it into alpha, we had three WAL files (D,E,F).
</p>
<p>
After restarting the postmaster, we had two WAL files (E,F).
</p>
<p>
My conjecture is that un-needed WAL files get cleaned out when a restart is done, but perhaps not in the normal course of events.
</p>
<p>
Doing a vacuum analyze on both databases did not cause a third WAL file 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.
</p>
<p>
We currently have plenty of space in /var for WAL files. After I recreated the databases using the procedure outlined above, we had recovered about 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 area. Since the evidence is all gone, I'm not certain what happened, but regardless, the procedure above places everything where we want it.
</p>
<p>
<a name = links><h2>Useful links</h2></a>
Note: PDF files are cached locally & hence may become stale
<ul>
<li><a href = "http://fts.postgresql.org/db/mw/">Search the postgresql mailing list archive</a>
<li><a href = "http://www.postgresql.org/idocs/">Search the postgresql interactive documents</a>
</ul>
<ul>
<li><a href ="http://techdocs.postgresql.org/">Links to other user-created documentation (similar to the page you're looking at)</a>
</ul>
<ul>
<li><a href = "http://www.postgresql.org">The PostgreSQL site</a> (among the US mirrors, <a href = "http://postgresql.crimelabs.net/">postgresql.crimelabs.net</a> seems to be the fastest)
<li><a href = "gb_intro_wp.pdf">GreatBridge's PostgreSQL white paper (nice intro)</a>
<li><a href = "http://www.de.postgresql.org/users-lounge/limitations.html">Size limitations of PostgreSQL</a>
<li><a href = "pgsql_tutorial.pdf">v7.1 PostgreSQL tutorial</a>
<li><a href = "pgsql_user.pdf">v7.1 PostgreSQL user guide</a>
<li><a href = "pgsql_programmer_guide.pdf">v7.1 PostgreSQL programmer's guide</a>
<li><a href = "pgsql_admin.pdf">v7.1 PostgreSQL administration manual</a>
<li><a href = "pgsql_reference.pdf">v7.1 PostgreSQL reference manual</a>
<li><a href = "pgsql_developer.pdf">v7.1 PostgreSQL developer's guide</a>
<li><a href = "momjian_pgsql_book.pdf">Bruce Momjian's PostgreSQL book</a>
<li><a href = "gb_admin_tuning_wp.pdf">GreatBridge's PostgreSQL tuning white paper. Some specifics may apply to their
distribution only, but the concepts are still valid.)</a>
</ul>
<ul>
<li><a href = "http://java.sun.com/products/jdbc/">JDBC home page</a>
<li><a href = "http://java.sun.com/products/jdk/1.2/docs/api/java/sql/package-summary.html">API for java.sql</a>
<li><a href = "http://java.sun.com/docs/books/tutorial/jdbc/">JDBC tutorial</a>
</ul>
</body>
</html>
pgsql_local.html (text/html, 8.8K) download
<html>
<head>
<title>PostgreSQL Notes and Links</title>
</head>
<body>
<h1>PostgreSQL notes and links</h1>
<ul>
<li><a href = "#local">Local Notes</a>
<li><a href = "#concepts">Concepts & Conjecture</a>
<li><a href = "#links">Links to other documention</a>
</ul>
<br>
<br>
<a name = local><h2>Local Notes</h2></a>
<ul>
<li><h3>We have made the following changes in /etc/postgresql/postgresql.conf:</h3>
<ul>
<li><b>tcpip_socket = 1</b> (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.)
<li><b>shared_buffers = 4096</b> (An increase to allow more caching -
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 )
<li><b>sort_mem = 2048</b> (This increases the space allocated in
RAM for sorts. it is measured in KB, so we have allocated 2MB.)<br><br>
</ul>
<li><h3>We have added this line to /etc/postgresql/pg_hba.conf:</h3>
<ul>
<li><b>host all xxx.xxx.xxx.xxx 255.255.255.255 trust</b> This
line says that for <b>all</b> databases, if a request comes
from <b>xxx.xxx.xxx.xxx</b>, it should be allowed
(<b>trust</b>ed). The netmask of <b>255.255.255.255</b> 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.
</ul>
</ul>
<a name = concepts><h2>Some general concepts and experiences we've had:</h2></a>
<p>
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.
</p>
<p>
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]
</p>
<p>
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:
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
To dump (export) a database, this command works:
[pg_dump demo >demo.dump]
</p>
<p>
To restore (import) a database, this command works:
[psql -d alpha -f demo.dump]
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
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
</p>
<p>
Some observed behavior:
</p>
<p>
After creating the demo data & doing a dump/restore of it into alpha, we had three WAL files (D,E,F).
</p>
<p>
After restarting the postmaster, we had two WAL files (E,F).
</p>
<p>
My conjecture is that un-needed WAL files get cleaned out when a restart is done, but perhaps not in the normal course of events.
</p>
<p>
Doing a vacuum analyze on both databases did not cause a third WAL file 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.
</p>
<p>
We currently have plenty of space in /var for WAL files. After I recreated the databases using the procedure outlined above, we had recovered about 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 area. Since the evidence is all gone, I'm not certain what happened, but regardless, the procedure above places everything where we want it.
</p>
<p>
<a name = links><h2>Useful links</h2></a>
Note: PDF files are cached locally & hence may become stale
<ul>
<li><a href = "http://fts.postgresql.org/db/mw/">Search the postgresql mailing list archive</a>
<li><a href = "http://www.postgresql.org/idocs/">Search the postgresql interactive documents</a>
</ul>
<ul>
<li><a href ="http://techdocs.postgresql.org/">Links to other user-created documentation (similar to the page you're looking at)</a>
</ul>
<ul>
<li><a href = "http://www.postgresql.org">The PostgreSQL site</a> (among the US mirrors, <a href = "http://postgresql.crimelabs.net/">postgresql.crimelabs.net</a> seems to be the fastest)
<li><a href = "gb_intro_wp.pdf">GreatBridge's PostgreSQL white paper (nice intro)</a>
<li><a href = "http://www.de.postgresql.org/users-lounge/limitations.html">Size limitations of PostgreSQL</a>
<li><a href = "pgsql_tutorial.pdf">v7.1 PostgreSQL tutorial</a>
<li><a href = "pgsql_user.pdf">v7.1 PostgreSQL user guide</a>
<li><a href = "pgsql_programmer_guide.pdf">v7.1 PostgreSQL programmer's guide</a>
<li><a href = "pgsql_admin.pdf">v7.1 PostgreSQL administration manual</a>
<li><a href = "pgsql_reference.pdf">v7.1 PostgreSQL reference manual</a>
<li><a href = "pgsql_developer.pdf">v7.1 PostgreSQL developer's guide</a>
<li><a href = "momjian_pgsql_book.pdf">Bruce Momjian's PostgreSQL book</a>
<li><a href = "gb_admin_tuning_wp.pdf">GreatBridge's PostgreSQL tuning white paper. Some specifics may apply to their
distribution only, but the concepts are still valid.)</a>
</ul>
<ul>
<li><a href = "http://java.sun.com/products/jdbc/">JDBC home page</a>
<li><a href = "http://java.sun.com/products/jdk/1.2/docs/api/java/sql/package-summary.html">API for java.sql</a>
<li><a href = "http://java.sun.com/docs/books/tutorial/jdbc/">JDBC tutorial</a>
</ul>
</body>
</html>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: nickf@ontko.com, sven.riedel@tu-clausthal.de
Subject: Re: Problems setting up DB at a different location
In-Reply-To: <NEBBLAAHGLEEPCGOBHDGIEPCDKAA.nickf@ontko.com>
References: <NEBBLAAHGLEEPCGOBHDGIEPCDKAA.nickf@ontko.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox