Ähnlich wie mySQL ist postgreSQL eine sehr bekannte und funktionsreiche freie Open-Source-Datenbank .
Zuvor haben wir mehrere Installationen besprochen, darunter LAMP-Stack-Installation, Apache2-Installation aus der Quelle, PHP5-Installation aus der Quelle und mySQL-Installation.
In diesem Artikel sehen wir uns an, wie man eine PostgreSQL-Datenbank installiert unter Linux aus dem Quellcode.
Schritt 1:PostgreSQL-Quellcode herunterladen
Wählen Sie auf der postgreSQL-Download-Site die Mirror-Site aus, die sich in Ihrem Land befindet.
# wget http://wwwmaster.postgresql.org/redir/198/f/source/v8.3.7/postgresql-8.3.7.tar.gz
Schritt 2:PostgreSQL installieren
# tar xvfz postgresql-8.3.7.tar.gz # cd postgresql-8.3.7 # ./configure checking for sgmlspl... no configure: creating ./config.status config.status: creating GNUmakefile config.status: creating src/Makefile.global config.status: creating src/include/pg_config.h config.status: creating src/interfaces/ecpg/include/ecpg_config.h config.status: linking ./src/backend/port/tas/dummy.s to src/backend/port/tas.s config.status: linking ./src/backend/port/dynloader/linux.c to src/backend/port/dynloader.c config.status: linking ./src/backend/port/sysv_sema.c to src/backend/port/pg_sema.c config.status: linking ./src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.c config.status: linking ./src/backend/port/dynloader/linux.h to src/include/dynloader.h config.status: linking ./src/include/port/linux.h to src/include/pg_config_os.h config.status: linking ./src/makefiles/Makefile.linux to src/Makefile.port # make make[3]: Leaving directory `/usr/save/postgresql-8.3.7/contrib/spi' rm -rf ./testtablespace mkdir ./testtablespace make[2]: Leaving directory `/usr/save/postgresql-8.3.7/src/test/regress' make[1]: Leaving directory `/usr/save/postgresql-8.3.7/src' make -C config all make[1]: Entering directory `/usr/save/postgresql-8.3.7/config' make[1]: Nothing to be done for `all'. make[1]: Leaving directory `/usr/save/postgresql-8.3.7/config' All of PostgreSQL successfully made. Ready to install. # make install make -C test/regress install make[2]: Entering directory `/usr/save/postgresql-8.3.7/src/test/regress' /bin/sh ../../../config/install-sh -c pg_regress '/usr/local/pgsql/lib/pgxs/src/test/regress/pg_regress' make[2]: Leaving directory `/usr/save/postgresql-8.3.7/src/test/regress' make[1]: Leaving directory `/usr/save/postgresql-8.3.7/src' make -C config install make[1]: Entering directory `/usr/save/postgresql-8.3.7/config' mkdir -p -- /usr/local/pgsql/lib/pgxs/config /bin/sh ../config/install-sh -c -m 755 ./install-sh '/usr/local/pgsql/lib/pgxs/config/install-sh' /bin/sh ../config/install-sh -c -m 755 ./mkinstalldirs '/usr/local/pgsql/lib/pgxs/config/mkinstalldirs' make[1]: Leaving directory `/usr/save/postgresql-8.3.7/config' PostgreSQL installation complete.
PostgreSQL ./configure-Optionen
Es folgen verschiedene Optionen, die an ./configure:
übergeben werden können- –prefix=PREFIX installiert architekturunabhängige Dateien in PREFIX. Der Standardinstallationsort ist /usr/local/pgsql
- –enable-integer-datetimes aktiviert die 64-Bit-Integer-Unterstützung für Datum/Uhrzeit
- –enable-nls[=LANGUAGES] Unterstützung der Muttersprache aktivieren
- –disable-shared erstellt keine gemeinsam genutzten Bibliotheken
- –disable-rpath Suchpfad der gemeinsam genutzten Bibliothek nicht in ausführbare Dateien einbetten
- –disable-spinlocks verwendet keine Spinlocks
- –enable-debug Build mit Debugging-Symbolen (-g)
- –enable-profiling Build mit aktivierter Profilerstellung
- –enable-dtrace mit DTrace-Unterstützung erstellen
- –enable-depend Automatisches Abhängigkeits-Tracking aktivieren
- –enable-cassert Assertionsprüfungen aktivieren (zur Fehlersuche)
- –enable-thread-safety Clientbibliotheken Thread-sicher machen
- –enable-thread-safety-force Thread-Sicherheit trotz fehlgeschlagenem Thread-Test erzwingen
- –disable-largefile Unterstützung für große Dateien auslassen
- –with-docdir=DIR Installieren Sie die Dokumentation in DIR [PREFIX/doc]
- – without-docdir die Dokumentation nicht installieren
- –with-includes=DIRS nach zusätzlichen Header-Dateien in DIRS suchen
- –with-libraries=DIRS nach zusätzlichen Bibliotheken in DIRS suchen
- –with-libs=DIRS alternative Schreibweise von –with-libraries
- –with-pgport=PORTNUM Standardportnummer ändern [5432]
- –with-tcl Tcl-Module erstellen (PL/Tcl)
- –with-tclconfig=DIR tclConfig.sh befindet sich im DIR
- –with-perl Perl-Module erstellen (PL/Perl)
- –with-python Python-Module erstellen (PL/Python)
- –with-gssapi mit GSSAPI-Unterstützung erstellen
- –with-krb5 Build mit Kerberos 5-Unterstützung
- –with-krb-srvnam=NAME standardmäßiger Dienstprinzipalname in Kerberos [postgres]
- –with-pam mit PAM-Unterstützung erstellen
- –with-ldap mit LDAP-Unterstützung erstellen
- –with-bonjour mit Bonjour-Unterstützung erstellen
- –with-openssl mit OpenSSL-Unterstützung erstellen
- –ohne-readline weder GNU Readline noch BSD Libedit zum Bearbeiten verwenden
- –with-libedit-preferred bevorzugt BSD Libedit gegenüber GNU Readline
- –with-ossp-uuid verwendet die OSSP-UUID-Bibliothek beim Erstellen von contrib/uuid-ossp
- –with-libxml mit XML-Unterstützung erstellen
- –with-libxslt XSLT-Unterstützung beim Erstellen von contrib/xml2 verwenden
- –with-system-tzdata=DIR Zeitzonendaten des Systems in DIR verwenden
- –ohne-zlib Zlib nicht verwenden
- –with-gnu-ld davon ausgehen, dass der C-Compiler GNU ld verwendet [default=no]
PostgreSQL-Installationsproblem 1:
Möglicherweise wird beim Ausführen von ./configure während der PostgreSQL-Installation die folgende Fehlermeldung angezeigt.
# ./configure checking for -lreadline... no checking for -ledit... no configure: error: readline library not found If you have readline already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-readline to disable readline support.
PostgreSQL-Installationslösung1:
Installieren Sie readline-devel und libtermcap-devel, um das obige Problem zu lösen.
# rpm -ivh libtermcap-devel-2.0.8-46.1.i386.rpm readline-devel-5.1-1.1.i386.rpm warning: libtermcap-devel-2.0.8-46.1.i386.rpm: Header V3 DSA signature: NOKEY, key ID 1e5e0159 Preparing... ########################################### [100%] 1:libtermcap-devel ########################################### [ 50%] 2:readline-devel ########################################### [100%]
Schritt 3:Überprüfen Sie die PostgreSQL-Verzeichnisstruktur
Stellen Sie nach der Installation sicher, dass die Verzeichnisse bin, doc, include, lib, man und share im Standardverzeichnis /usr/local/pgsql wie unten gezeigt erstellt wurden.
# ls -l /usr/local/pgsql/ total 24 drwxr-xr-x 2 root root 4096 Apr 8 23:25 bin drwxr-xr-x 3 root root 4096 Apr 8 23:25 doc drwxr-xr-x 6 root root 4096 Apr 8 23:25 include drwxr-xr-x 3 root root 4096 Apr 8 23:25 lib drwxr-xr-x 4 root root 4096 Apr 8 23:25 man drwxr-xr-x 5 root root 4096 Apr 8 23:25 share
Schritt 4:PostgreSQL-Benutzerkonto erstellen
# adduser postgres # passwd postgres Changing password for user postgres. New UNIX password: Retype new UNIX password: passwd: all authentication tokens updated successfully.
Schritt 5:PostgreSQL-Datenverzeichnis erstellen
Erstellen Sie das Postgres-Datenverzeichnis und machen Sie den Postgres-Benutzer zum Besitzer.
# mkdir /usr/local/pgsql/data # chown postgres:postgres /usr/local/pgsql/data # ls -ld /usr/local/pgsql/data drwxr-xr-x 2 postgres postgres 4096 Apr 8 23:26 /usr/local/pgsql/data
Schritt 6:PostgreSQL-Datenverzeichnis initialisieren
Bevor Sie mit dem Erstellen einer PostgreSQL-Datenbank beginnen können, sollte das leere Datenverzeichnis, das im obigen Schritt erstellt wurde, mit dem initdb-Befehl wie unten gezeigt initialisiert werden.
# su - postgres # /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data/ The files belonging to this database system will be owned by user postgres This user must also own the server process. The database cluster will be initialized with locale en_US.UTF-8. The default database encoding has accordingly been set to UTF8. The default text search configuration will be set to "english". fixing permissions on existing directory /usr/local/pgsql/data ... ok creating subdirectories ... ok selecting default max_connections ... 100 selecting default shared_buffers/max_fsm_pages ... 32MB/204800 creating configuration files ... ok creating template1 database in /usr/local/pgsql/data/base/1 ... ok initializing pg_authid ... ok initializing dependencies ... ok creating system views ... ok loading system objects' descriptions ... ok creating conversions ... ok creating dictionaries ... ok setting privileges on built-in objects ... ok creating information schema ... ok vacuuming database template1 ... ok copying template1 to template0 ... ok copying template1 to postgres ... ok WARNING: enabling "trust" authentication for local connections You can change this by editing pg_hba.conf or using the -A option the next time you run initdb. Success. You can now start the database server using: /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data or /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
Schritt 7:Überprüfen Sie das PostgreSQL-Datenverzeichnis
Stellen Sie sicher, dass alle Postgres-DB-Konfigurationsdateien (z. B. postgresql.conf) wie unten gezeigt im Datenverzeichnis erstellt werden.
$ ls -l /usr/local/pgsql/data total 64 drwx------ 5 postgres postgres 4096 Apr 8 23:29 base drwx------ 2 postgres postgres 4096 Apr 8 23:29 global drwx------ 2 postgres postgres 4096 Apr 8 23:29 pg_clog -rw------- 1 postgres postgres 3429 Apr 8 23:29 pg_hba.conf -rw------- 1 postgres postgres 1460 Apr 8 23:29 pg_ident.conf drwx------ 4 postgres postgres 4096 Apr 8 23:29 pg_multixact drwx------ 2 postgres postgres 4096 Apr 8 23:29 pg_subtrans drwx------ 2 postgres postgres 4096 Apr 8 23:29 pg_tblspc drwx------ 2 postgres postgres 4096 Apr 8 23:29 pg_twophase -rw------- 1 postgres postgres 4 Apr 8 23:29 PG_VERSION drwx------ 3 postgres postgres 4096 Apr 8 23:29 pg_xlog -rw------- 1 postgres postgres 16592 Apr 8 23:29 postgresql.conf
Schritt 8:PostgreSQL-Datenbank starten
Verwenden Sie den Befehl postgres postmaster, um den postgreSQL-Server wie unten gezeigt im Hintergrund zu starten.
$ /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data >logfile 2>&1 & [1] 2222 $ cat logfile LOG: database system was shut down at 2009-04-08 23:29:50 PDT LOG: autovacuum launcher started LOG: database system is ready to accept connections
Schritt 9:PostgreSQL-DB erstellen und Installation testen
Erstellen Sie eine Testdatenbank und stellen Sie eine Verbindung zu ihr her, um sicherzustellen, dass die Installation wie unten gezeigt erfolgreich war. Sobald Sie beginnen, die Datenbank zu verwenden, erstellen Sie häufig Sicherungen, wie im Artikel zum Sichern und Wiederherstellen von PostgreSQL beschrieben.
$ /usr/local/pgsql/bin/createdb test $ /usr/local/pgsql/bin/psql test Welcome to psql 8.3.7, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help with psql commands \g or terminate with semicolon to execute query \q to quit test=#