Instalacja i konfiguracja bazy danych PostgreSQL w OpenWrt
Ostatnia zmiana: 2016-05-22 13:01
Do instalacji niezbędne jest dużo miejsca w pamięci flash lub
extroot oraz zewnętrzny nośnik - np. na usb - do przechowywania samej bazy danych. Poniższy poradnik wykonano w oparciu o OpenWrt Chaos Calmer 15.05.1
Instalacja
# opkg update
# opkg install pgsql-server
Konfiguracja
Domyślna konfiguracja jest w pliku
/etc/config/postgresql
# uci show postgresql
postgresql.config=postgresql
postgresql.config.PGUSER=postgres
postgresql.config.PGDATA=/var/postgresql/data
postgresql.config.PGLOG=/var/postgresql/data/postgresql.log
postgresql.config.PG_CTL=/usr/bin/pg_ctl
Należy zmienić odpowiednie ścieżki; w tym przykładzie zakładamy ze baza będzie położna w
/mnt/data/pgsql/data:
# uci set postgresql.config.PGDATA=/mnt/data/pgsql/data
# uci set postgresql.config.PGLOG=/mnt/data/pgsql/data/pgsql.log
# uci commit postgresql
Następnie należy zainicjować bazę danych. Wymaga to wykonania następujących poleceń:
# opkg install shadow-su
# mkdir -p /mnt/data/pgsql/data
# chown postgres /mnt/data/pgsql/data/
# sed -i "s|/var/run/postgres:/bin/false|/var/run/postgres:/bin/sh|" /etc/passwd
# mkdir -p /var/run/postgres
# su - postgres
postgres@OpenWrt:/tmp/run/postgres$ LC_COLLATE="C" initdb --pwprompt -D /mnt/data/pgsql/data/
Sam proces inicjacji trwa parę minut, wygląda on następująco:
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 "C".
The default database encoding has accordingly been set to "SQL_ASCII".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /mnt/data/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 8000kB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
creating template1 database in /mnt/data/pgsql/data/base/1 ... ok
initializing pg_authid ... ok
Enter new superuser password:
Enter it again:
setting password ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... not supported on this platform
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
syncing data to disk ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
postgres -D /mnt/data/pgsql/data/
or
pg_ctl -D /mnt/data/pgsql/data/ -l logfile start
postgres@OpenWrt:/tmp/run/postgres$ exit
Można już uruchomić bazę danych
# /etc/init.d/postgresql start
Test połączenia
Próbujemy dostać się do bazy:
# psql -d template1 -U postgres
psql (9.4.4)
Type "help" for help.
template1=# select * from version();
version
--
PostgreSQL 9.4.4 on mips-openwrt-linux-gnu, compiled by mips-openwrt-linux-uclibc-gcc (OpenWrt/Linaro GCC 4.8-2014.04 r47196) 4.8.3, 32-bit
(1 row)
template1=#\q