next up previous contents index
Next: Operational Questions Up: Additional Resources Previous: User Client Questions

Subsections

Administrative Questions

   
3.1) Why does initdb fail?

Try these:

3.2) How do I install POSTGRESQL somewhere other than /usr/local/pgsql?

The simplest way is to specify the -prefix option when running configure. If you forgot to do that, you can edit Makefile.global and change POSTGRESDIR accordingly, or create a Makefile.custom and define POSTGRESDIR there.

   
3.3)When I start the postmaster, I get a Bad System Call or core dumped message. Why?

It could be a variety of problems, but first check to see that you have System V extensions installed in your kernel. POSTGRESQL requires kernel support for shared memory and semaphores.

3.4) When I try to start the postmaster, I get IpcMemoryCreate errors. Why?

You either do not have shared memory configured properly in your kernel or you need to enlarge the shared memory available in the kernel. The exact amount you need depends on your architecture and how many buffers and backend processes you configure for the postmaster. For most systems, with default numbers of buffers and processes, you need a minimum of ~1MB.

3.5) When I try to start the postmaster, I get IpcSemaphoreCreate errors. Why?

If the error message is IpcSemaphoreCreate: semget failed (No space left on device) then your kernel is not configured with enough semaphores. Postgres needs one semaphore per potential backend process. A temporary solution is to start the postmaster with a smaller limit on the number of backend processes. Use -N with a parameter less than the default of 32. A more permanent solution is to increase your kernel's SEMMNS and SEMMNI parameters.

If the error message is something else, you might not have semaphore support configured in your kernel at all. 

   
3.6) How do I prevent other hosts from accessing my POSTGRESQL database?

By default, POSTGRESQL only allows connections from the local machine using Unix domain sockets. Other machines will not be able to connect unless you add the -i flag to the postmaster, and enable host-based authentication by modifying the file $PGDATA/pg_hba.conf accordingly. This will allow TCP/IP connections.

3.7) Why can't I connect to my database from another machine?

The default configuration allows only Unix domain socket connections from the local machine. To enable TCP/IP connections, make sure the postmaster has been started with the -i option, and add an appropriate host entry to the file pgsql/data/pg_hba.conf.  

3.8) Why can't I access the database as the root user?

You should not create database users with user id 0 (root). They will be unable to access the database. This is a security precaution because of the ability of users to dynamically link object modules into the database engine.

3.9) All my servers crash under concurrent table access. Why?

This problem can be caused by a kernel that is not configured to support semaphores.

  
3.10) How do I tune the database engine for better performance?

Certainly, indices can speed up queries. The EXPLAIN command allows you to see how POSTGRESQL is interpreting your query, and which indices are being used.

If you are doing a lot of INSERTs, consider doing them in a large batch using the COPY  command. This is much faster than individual INSERTs. Second, statements not in a BEGIN WORK/COMMIT transaction block are considered to be in their own transaction. Consider performing several statements in a single transaction block. This reduces the transaction overhead. Also consider dropping and recreating indices when making large data changes.

There are several tuning options. You can disable fsync() by starting the postmaster with a -o -F option. This will prevent fsync()'s from flushing to disk after every transaction.

 You can also use the postmaster -B option to increase the number of shared memory buffers used by the backend processes. If you make this parameter too high, the postmaster may not start because you've exceeded your kernel's limit on shared memory space. Each buffer is 8K and the default is 64 buffers.

You can also use the backend -S option to increase the maximum amount of memory used by the backend process for temporary sorts. The -S value is measured in kilobytes, and the default is 512 (ie, 512K). 

You can also use the CLUSTER command to group data in tables to match an index. See the CLUSTER manual page for more details. 

  
3.11) What debugging features are available?

POSTGRESQL has several features that report status information that can be valuable for debugging purposes.

First, by running configure with the -enable-cassert option, many assert()'s monitor the progress of the backend and halt the program when something unexpected occurs.

Both postmaster and postgres have several debug options available. First, whenever you start the postmaster, make sure you send the standard output and error to a log file, like:

 

        cd /usr/local/pgsql 
        ./bin/postmaster > server.log 2>&1 &
 

This will put a server.log file in the top-level POSTGRESQL directory. This file contains useful information about problems or errors encountered by the server. Postmaster has a -d option that allows even more detailed information to be reported. The -d option takes a number that specifies the debug level. Be warned that high debug level values generate large log files.

If the postmaster is not running, you can actually run the postgres backend from the command line, and type your SQL statement directly. This is recommended only for debugging purposes. Note that a newline terminates the query, not a semicolon. If you have compiled with debugging symbols, you can use a debugger to see what is happening. Because the backend was not started from the postmaster, it is not running in an identical environment and locking/backend interaction problems may not be duplicated.

If the postmaster is running, start psql in one window, then find the PID of the postgres process used by psql. Use a debugger to attach to the postgres PID. You can set breakpoints in the debugger and issue queries from psql. If you are debugging postgres start-up, you can set PGOPTIONS="-W n", then start psql. This will cause start-up to delay for n seconds so you can attach with the debugger and trace through the start-up sequence.

The postgres program has -s, -A, and -t options that can be very useful for debugging and performance measurements.

You can also compile with profiling to see what functions are taking execution time. The backend profile files will be deposited in the pgsql/data/base/dbname directory. The client profile file will be put in the client's current directory. 

  
3.12) I get ``Sorry, too many clients'' when trying to connect. Why?

You need to increase the postmaster's limit on how many concurrent backend processes it can start.

In POSTGRESQL 6.5 and up, the default limit is 32 processes. You can increase it by restarting the postmaster with a suitable -N value. With the default configuration you can set -N as large as 1024. If you need more, increase MAXBACKENDS in include/config.h and rebuild. You can set the default value of -N at configuration time, if you like, using configure's -with-maxbackends switch.

Note that if you make -N larger than 32, you must also increase -B beyond its default of 64; -B must be at least twice -N, and probably should be more than that for best performance. For large numbers of backend processes, you are also likely to find that you need to increase various Unix kernel configuration parameters. Things to check include the maximum size of shared memory blocks, SHMMAX; the maximum number of semaphores, SEMMNS and SEMMNI; the maximum number of processes, NPROC; the maximum number of processes per user, MAXUPRC; and the maximum number of open files, NFILE and NINODE. The reason that POSTGRESQL has a limit on the number of allowed backend processes is so your system won't run out of resources.

In POSTGRESQL versions prior to 6.5, the maximum number of backends was 64, and changing it required a rebuild after altering the MaxBackendId constant in include/storage/sinvaladt.h.

3.13) What are the pg_sorttempNNN.NN files in my database directory?

They are temporary files generated by the query executor. For example, if a sort needs to be done to satisfy an ORDER BY, and the sort requires more space than the backend's -S parameter allows, then temporary files are created to hold the extra data.

The temporary files should be deleted automatically, but might not if a backend crashes during a sort. If you have no backends running at the time, it is safe to delete the pg_tempNNN.NN files. 


next up previous contents index
Next: Operational Questions Up: Additional Resources Previous: User Client Questions
Bruce Momjian
2001-05-09