README-server 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. $OpenBSD: README-server,v 1.22 2017/05/23 14:17:00 sthen Exp $
  2. +-----------------------------------------------------------------------
  3. | Running ${FULLPKGNAME} on OpenBSD
  4. +-----------------------------------------------------------------------
  5. At least two different accounts are involved when working with PostgreSQL:
  6. One is an OpenBSD userid, '_postgresql', which is used as the userid of files
  7. that are part of PostgreSQL. The other, usually named 'postgres', is not an
  8. OpenBSD userid, i.e. you will not find it in /etc/passwd, but an account
  9. internal to the database system. The 'postgres' account is called the dba
  10. account (database administrator) and is created when a new database is
  11. initialized using the initdb command.
  12. If you are installing PostgreSQL for the first time, you have to create
  13. a default database first. In the following example we install a database
  14. in /var/postgresql/data with a dba account 'postgres' and md5 authentication.
  15. We will be prompted for a password to protect the dba account:
  16. # su - _postgresql
  17. $ mkdir /var/postgresql/data
  18. $ initdb -D /var/postgresql/data -U postgres -A md5 -W
  19. Please note that by default the cluster's encoding will be SQL_ASCII. If
  20. you want to have another default encoding, use the option -E with initdb:
  21. $ initdb -D /var/postgresql/data -U postgres -E UTF8 -A md5 -W
  22. If your cluster is already created, you can specify another encoding when
  23. you create a new database with this command:
  24. CREATE DATABASE xxx TEMPLATE template0 ENCODING 'xxx' ;
  25. It is strongly advised that you do not work with the postgres dba account
  26. other than creating more users and/or databases or for administrative tasks.
  27. Use the PostgreSQL permission system to make sure that a database is only
  28. accessed by programs/users that have the right to do so.
  29. Please consult the PostgreSQL website for more information, especially when
  30. you are upgrading an existing database installation.
  31. Network Connections
  32. ===================
  33. To allow connections over TCP (and other options) edit the file:
  34. /var/postgresql/data/postgresql.conf
  35. and also edit the pg_hba.conf (in the same directory) making the
  36. appropriate changes to allow connection from your network.
  37. To allow SSL connections, edit postgresql.conf and enable the
  38. 'ssl' keyword, and create keys and certificates:
  39. # su - _postgresql
  40. $ cd /var/postgresql/data
  41. $ umask 077
  42. $ openssl genrsa -out server.key 2048
  43. $ openssl req -new -key server.key -out server.csr
  44. Either take the CSR to a Certifying Authority (CA) to sign your
  45. certificate, or self-sign it:
  46. $ openssl x509 -req -days 365 -in server.csr \
  47. -signkey server.key -out server.crt
  48. Restart PostgreSQL to allow these changes to take effect.
  49. Tuning for busy servers
  50. =======================
  51. The default sizes in the GENERIC kernel for SysV semaphores are only
  52. just large enough for a database with the default configuration
  53. (max_connections 40) if no other running processes use semaphores.
  54. In other cases you will need to increase the limits. Adding the
  55. following in /etc/sysctl.conf will be reasonable for many systems:
  56. kern.seminfo.semmni=60
  57. kern.seminfo.semmns=1024
  58. To serve a large number of connections (>250), you may need higher
  59. values for the above.
  60. You may also want to tune the max_connect value in the
  61. postgresql.conf file to increase the number of connections to the
  62. backend.
  63. By default, the _postgresql user, and so the postmaster and backend
  64. processes run in the login(1) class of "daemon". On a busy server,
  65. it may be advisable to put the _postgresql user and processes in
  66. their own login(1) class with tuned resources, such as more open
  67. file descriptors (used for network connections as well as files),
  68. possibly more memory, etc.
  69. For example, add this to the login.conf(5) file:
  70. postgresql:\
  71. :openfiles=768:\
  72. :tc=daemon:
  73. Rebuild the login.conf.db file if necessary:
  74. # [ -f /etc/login.conf.db ] && cap_mkdb /etc/login.conf
  75. For more than about 250 connections, these numbers should be
  76. increased. Please report any changes and experiences to the package
  77. maintainers so that we can update this file for future versions.
  78. Upgrade Howto (for a major upgrade)
  79. ===================================
  80. If you didn't install PostgreSQL by following this README,
  81. you must adapt these instructions to your setup.
  82. Option 1: Dump and Restore
  83. --------------------------
  84. This will work for any upgrade from any major version of PostgreSQL
  85. to the current version.
  86. 1) Backup all your data:
  87. # su _postgresql -c "pg_dumpall -U postgres > /var/postgresql/full.sqldump"
  88. 2) Shutdown the server:
  89. # rcctl stop postgresql
  90. 3) Upgrade your PostgreSQL package with pkg_add.
  91. # pkg_add -ui postgresql-server
  92. 4) Backup your old data directory:
  93. # mv /var/postgresql/data /var/postgresql/data-${PREV_MAJOR}
  94. 5) Create a new data directory (using -E UTF8 if appropriate):
  95. # su _postgresql -c "mkdir /var/postgresql/data"
  96. # su _postgresql -c "initdb -D /var/postgresql/data -U postgres -A md5 -W"
  97. 6) Restore your old pg_hba.conf and (if used) SSL certificates
  98. # su _postgresql -c \
  99. "cp /var/postgresql/data-${PREV_MAJOR}/pg_hba.conf /var/postgresql/data/"
  100. # su _postgresql -c \
  101. "cp /var/postgresql/data-${PREV_MAJOR}/server.{crt,key} /var/postgresql/data/"
  102. Some postgresql.conf settings changed or disappeared in this version.
  103. Examine your old file for local changes and apply them to the new version.
  104. 7) Start PostgreSQL:
  105. # rcctl start postgresql
  106. 8) Restore your data:
  107. # su _postgresql -c "psql -U postgres < /var/postgresql/full.sqldump"
  108. Option 2: pg_upgrade
  109. --------------------
  110. This will work for an upgrade from the previous major version of
  111. PostgreSQL supported by OpenBSD to the current version, and should be
  112. faster than a dump and reload, especially for large databases.
  113. 1) Shutdown the server:
  114. # rcctl stop postgresql
  115. 2) Upgrade your PostgreSQL package with pkg_add.
  116. # pkg_add postgresql-pg_upgrade
  117. 3) Backup your old data directory:
  118. # mv /var/postgresql/data /var/postgresql/data-${PREV_MAJOR}
  119. 4) Create a new data directory (using -E UTF8 if appropriate):
  120. # su _postgresql -c "mkdir /var/postgresql/data"
  121. # su _postgresql -c "initdb -D /var/postgresql/data -U postgres -A md5 -W"
  122. 5) Restore your old pg_hba.conf and (if used) SSL certificates
  123. # su _postgresql -c \
  124. "cp /var/postgresql/data-${PREV_MAJOR}/pg_hba.conf /var/postgresql/data/"
  125. # su _postgresql -c \
  126. "cp /var/postgresql/data-${PREV_MAJOR}/server.{crt,key} /var/postgresql/data/"
  127. Some postgresql.conf settings changed or disappeared in this version.
  128. Examine your old file for local changes and apply them to the new version.
  129. 6) Temporarily support connecting without a password for local users by
  130. editing pg_hba.conf to include "local all postgres trust"
  131. # su _postgresql -c "vi /var/postgresql/data/pg_hba.conf"
  132. 7) Run pg_upgrade:
  133. # su _postgresql -c "cd /var/postgresql && \
  134. pg_upgrade -b /usr/local/bin/postgresql-${PREV_MAJOR}/ -B /usr/local/bin \
  135. -U postgres -d /var/postgresql/data-${PREV_MAJOR}/ -D /var/postgresql/data"
  136. 8) Remove "local all postgres trust" line from pg_hba.conf
  137. # su _postgresql -c "vi /var/postgresql/data/pg_hba.conf"
  138. 9) Start PostgreSQL:
  139. # rcctl start postgresql
  140. Clients/Frontends
  141. =================
  142. Many applications can use the PostgreSQL database right away. To facilitate
  143. administration of a PostgreSQL database, two clients are notable:
  144. www/phppgadmin A web based user interface that uses PHP5
  145. databases/pgadmin3 A graphical user interface that uses wxWidgets