[F20] Installazione postgresql e funzionamento in locale

Salve a tutti.
Ho installato PostgreSQL e fino adesso non ho mai avuto problemi ad utilizzarlo sul server dell’università. Ora ho riscontrato dei problemi provando ad utilizzarlo in locale,
Ho seguito le istruzioni su https://fedoraproject.org/wiki/PostgreSQL però nel momento in cui ho provato a eseguire:

# su - postgres

il risultato dopo aver inserito la password è questo:

su: Autenticazione fallita

Ho provato a eseguire il comando da root e il risultato è questo:

Non è consentito eseguire il server PostgreSQL come "root". Il server deve essere avviato con un ID utente non privilegiato per prevenire possibili problemi di sicurezza. Consulta la documentazione per avere maggiori informazioni su come avviare il server correttamente.

Se provo ad usare il comando che utilizzo normalmente per accedere all’interfaccia interattiva il risultato è questo:

# psql psql: connessione al server fallita: File o directory non esistente Verifica che il server locale sia in funzione e che accetti connessioni sul socket di dominio Unix "/var/run/postgresql/.s.PGSQL.5432"

In fine se provo ad eseguire da root:

# su - postgres

sembrerebbe loggarmi ma a parte il non capirne il senso ottengo questo risultato:

Ultimo accesso: mer mag 6 15.51.03 CEST 2015 su pts/0

e se provo a chiamare:

-bash-4.2$ psql

ottengo:

psql: connessione al server fallita: File o directory non esistente Verifica che il server locale sia in funzione e che accetti connessioni sul socket di dominio Unix "/var/run/postgresql/.s.PGSQL.5432"

Qualcuno può aiutarmi?

Ciao.

Per prima cosa, mostraci:

# systemctl status postgresql

# systemctl status postgresql postgresql.service - PostgreSQL database server Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled) Active: inactive (dead)

Devi avviare il servizio postgresql. Prova semplicemente con:

# systemctl start postgresql

Se incontri qualche errore, posta qui l’output del comando indicato. Altrimenti, riprova ad operare sul tuo database come di consueto.

il risultato:

# systemctl start postgresql Job for postgresql.service failed. See 'systemctl status postgresql.service' and 'journalctl -xn' for details.

La prima volta devi eseguire

postgresql-setup initdb

Comunque, come consigliato dall’output di post #5, il log seguente potrebbe essere chiarificatore:

# journalctl -xn

Allora eseguito

$ sudo postgresql-setup initdb Initializing database ... OK

poi

[code]# systemctl start postgresql
[root@localhost luca]# systemctl status postgresql
postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled)
Active: active (running) since mer 2015-05-06 20:48:55 CEST; 6s ago
Process: 4039 ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o -p ${PGPORT} -w -t 300 (code=exited, status=0/SUCCESS)
Process: 4032 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
Main PID: 4042 (postgres)
CGroup: /system.slice/postgresql.service
├─4042 /usr/bin/postgres -D /var/lib/pgsql/data -p 5432
├─4043 postgres: logger process
├─4045 postgres: checkpointer process
├─4046 postgres: writer process
├─4047 postgres: wal writer process
├─4048 postgres: autovacuum launcher process
└─4049 postgres: stats collector process

mag 06 20:48:54 localhost.localdomain systemd[1]: Starting PostgreSQL databas…
mag 06 20:48:54 localhost.localdomain pg_ctl[4039]: LOG: redirezione dell’ou…
mag 06 20:48:54 localhost.localdomain pg_ctl[4039]: SUGGERIMENTO: I prossimi…
mag 06 20:48:55 localhost.localdomain systemd[1]: Started PostgreSQL database…
Hint: Some lines were ellipsized, use -l to show in full.[/code]

e infine

$ journalctl -xn -- Logs begin at mar 2015-04-28 18:22:09 CEST, end at mer 2015-05-06 20:49:24 CE mag 06 18:15:45 localhost.localdomain su[3396]: (to root) luca on pts/0 mag 06 18:15:45 localhost.localdomain su[3396]: pam_unix(su:session): session op mag 06 20:48:30 localhost.localdomain su[4000]: pam_unix(su-l:auth): authenticat mag 06 20:48:30 localhost.localdomain su[4000]: pam_succeed_if(su-l:auth): requi mag 06 20:48:32 localhost.localdomain su[4000]: FAILED SU (to postgres) luca on mag 06 20:48:45 localhost.localdomain su[4004]: (to root) luca on pts/0 mag 06 20:48:45 localhost.localdomain su[4004]: pam_unix(su:session): session op mag 06 20:49:23 localhost.localdomain su[4053]: pam_unix(su-l:auth): authenticat mag 06 20:49:23 localhost.localdomain su[4053]: pam_succeed_if(su-l:auth): requi mag 06 20:49:24 localhost.localdomain su[4053]: FAILED SU (to postgres) luca on lines 1-11/11 (END)


Aggiungo che ho riprovato:

$ su - postgres su: Autenticazione fallita

ma facendo:

[code]$ su

su - postgres

Ultimo accesso: mer mag 6 15.55.30 CEST 2015 su pts/0
Ultimo accesso fallito: mer mag 6 20.54.17 CEST 2015 su pts/0
Si è verificato un tentativo di login 3 fallito dall’ultimo tentativo di login con successo.
-bash-4.2$ psql
psql (9.3.6)
Digita “help” per avere un aiuto.

postgres=#
[/code]

e quindi dovrebbe funzionare.
mentre se faccio

# postgres Non è consentito eseguire il server PostgreSQL come "root". Il server deve essere avviato con un ID utente non privilegiato per prevenire possibili problemi di sicurezza. Consulta la documentazione per avere maggiori informazioni su come avviare il server correttamente.

se provo

$ su - postgres su: Autenticazione fallita

quindi dovrei farlo come root perché sennò non funziona. Non riesco a capire la differenza tra quest’ultimo eseguito direttamente da root e non

Ci sono delle differenze nei tre modi di operare.

Nel primo caso, facendo “su - postgres”, ti autentichi come utente ‘postgres’, non sei più ‘root’. L’output seguente ti può aiutare in questi casi:

$ whoami

Successivamente avvii “psql”, che è un’interfaccia a linea di comando per gestire i database.

Nel secondo caso invece, tenti di avviare l’intero server (e non il programma psql) direttamente come “root”.

Qui sinceramente non saprei perché non puoi loggarti come ‘postgres’ direttamente da semplice utente…
Probabilmente perché, essendo l’utente ‘postgres’ l’amministratore del server, esso è configurato in maniera tale da essere accessibile solo da shell privilegiate.

Non puoi entrare perché è bloccato, come è giusto che sia, e solo root può entrare su account bloccati.
Un conto è la password dell’utente del sistema chiamato postgres un conto è la password dell’utente del database chiamato postgres. L’utilizzo delle credenziali del sistema operativo per gestire il database è soltanto uno dei possibili metodi.

Maggiori informazioni su: http://serverfault.com/a/325596/236028

[quote=frafra]Non puoi entrare perché è bloccato, come è giusto che sia, e solo root può entrare su account bloccati.
Un conto è la password dell’utente del sistema chiamato postgres un conto è la password dell’utente del database chiamato postgres. L’utilizzo delle credenziali del sistema operativo per gestire il database è soltanto uno dei possibili metodi.

Maggiori informazioni su: http://serverfault.com/a/325596/236028[/quote]

Scusa ma non ho capito. Seguendo le istruzioni nel link faccio:

sudo -u postgres psql postgres

e mi da:

could not change directory to "/home/luca": Permesso negato psql: connessione al server fallita: File o directory non esistente Verifica che il server locale sia in funzione e che accetti connessioni sul socket di dominio Unix "/var/run/postgresql/.s.PGSQL.5432"

e se riprovo accedendo prima come root e poi come utente “postgres”

[luca@localhost ~]$ su Password: [root@localhost luca]# su - postgres Ultimo accesso: mer giu 24 12.11.07 CEST 2015 su pts/0 -bash-4.3$ psql psql: connessione al server fallita: File o directory non esistente Verifica che il server locale sia in funzione e che accetti connessioni sul socket di dominio Unix "/var/run/postgresql/.s.PGSQL.5432"

Va bhe. Trascurando il perché e per come mi faccia entrare in un modo piuttosto che nell’altro. Vorrei creare un database in locale mi sapete spiegare questo errore?

[code]systemctl start postgresql
Job for postgresql.service failed. See “systemctl status postgresql.service” and “journalctl -xe” for details.
[root@localhost luca]# systemctl status postgresql.service
● postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since lun 2015-06-29 18:49:36 CEST; 16s ago
Process: 5325 ExecStartPre=/usr/libexec/postgresql-check-db-dir %N (code=exited, status=1/FAILURE)

giu 29 18:49:36 localhost.localdomain systemd[1]: Starting PostgreSQL database server…
giu 29 18:49:36 localhost.localdomain systemd[1]: postgresql.service: control process exited, code=exited status=1
giu 29 18:49:36 localhost.localdomain systemd[1]: Failed to start PostgreSQL database server.
giu 29 18:49:36 localhost.localdomain systemd[1]: Unit postgresql.service entered failed state.
giu 29 18:49:36 localhost.localdomain systemd[1]: postgresql.service failed.
[/code]

Non è un problema di accesso, è il servizio che non è attivo.

Hai inizializzato il database? Hai per caso modificato la configurazione?
https://fedoraproject.org/wiki/PostgreSQL#Installation

Come evidenziato dal post #8

[quote]# systemctl start postgresql
[root@localhost luca]# systemctl status postgresql
postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled)
Active: active (running) since mer 2015-05-06 20:48:55 CEST; 6s ago


[/quote]
il servizio è running ma non è abilitato. Prima di startarlo bisogna dare:

#systemctl enable postgresql
Ciao
Sergio

[quote=idraulico]il servizio è running ma non è abilitato. Prima di startarlo bisogna dare:

#systemctl enable postgresql [/quote]
Vero, il servizio non è abilitato, ma il problema non sembra quello (almeno a guardare il post 12):

[quote=Paletta]systemctl start postgresql
Job for postgresql.service failed
. See “systemctl status postgresql.service” and “journalctl -xe” for details.

systemctl status postgresql.service

[cut]
Active: failed (Result: exit-code) since lun 2015-06-29 18:49:36 CEST; 16s ago
Process: 5325 ExecStartPre=/usr/libexec/postgresql-check-db-dir %N (code=exited, status=1/FAILURE)

giu 29 18:49:36 localhost.localdomain systemd[1]: postgresql.service: control process exited, code=exited status=1
giu 29 18:49:36 localhost.localdomain systemd[1]: Failed to start PostgreSQL database server.
giu 29 18:49:36 localhost.localdomain systemd[1]: Unit postgresql.service entered failed state.
giu 29 18:49:36 localhost.localdomain systemd[1]: postgresql.service failed.[/quote]

Se il servizio non riesce a partire manualmente, non partirà neppure abilitandolo.

[quote=idraulico]Come evidenziato dal post #8

[quote]# systemctl start postgresql
[root@localhost luca]# systemctl status postgresql
postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled)
Active: active (running) since mer 2015-05-06 20:48:55 CEST; 6s ago


[/quote]
il servizio è running ma non è abilitato. Prima di startarlo bisogna dare:

#systemctl enable postgresql
Ciao
Sergio[/quote]

Ho fatto quanto hai detto ma non restituisce nulla e gli errori sembrano rimanere.

[quote=frafra]Non è un problema di accesso, è il servizio che non è attivo.

Hai inizializzato il database? Hai per caso modificato la configurazione?
https://fedoraproject.org/wiki/PostgreSQL#Installation[/quote]

Io ho inizializzato il database come indicato su http://www.postgresql.org/docs/9.1 .
Ho seguito le istruzioni per avviare il server in background:

[luca@localhost ~]$ su Password: [root@localhost luca]# sudo - postgres [root@localhost luca]# su - postgres Ultimo accesso: ven lug 3 11.42.44 CEST 2015 su pts/0

ed avviato il server con:

-bash-4.3$ postgres -D /usr/local/pgsql/data >logfile 2>&1 & [1] 13502

e sono entrato nel terminale:

-bash-4.3$ psql postgres psql (9.4.4) Digita "help" per avere un aiuto. postgres=#

Però se do :

[code][root@localhost luca]# systemctl status postgresql.service
● postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since ven 2015-07-03 11:40:19 CEST; 14min ago

lug 03 11:40:19 localhost.localdomain systemd[1]: Starting PostgreSQL databas…
lug 03 11:40:19 localhost.localdomain systemd[1]: postgresql.service: control…
lug 03 11:40:19 localhost.localdomain systemd[1]: Failed to start PostgreSQL …
lug 03 11:40:19 localhost.localdomain systemd[1]: Unit postgresql.service ent…
lug 03 11:40:19 localhost.localdomain systemd[1]: postgresql.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost luca]#
[/code]

gli errori rimangono e non capisco se mi darà problemi o se, visto che mi fa entrare tranquillamente nel terminale, ora funzioni.

PS: se può essere utile:

[code][root@localhost luca]# journalctl -xn
– Logs begin at mar 2015-04-28 18:22:04 CEST, end at ven 2015-07-03 12:02:04 CEST. –
lug 03 12:02:04 localhost.localdomain systemd[1]: Starting PostgreSQL database server…
– Subject: L’unità postgresql.service inizia la fase di avvio
– Defined-By: systemd
– Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel

– L’unità postgresql.service ha iniziato la fase di avvio.
lug 03 12:02:04 localhost.localdomain postgresql-check-db-dir[13587]: An old version of the database format was found.
lug 03 12:02:04 localhost.localdomain postgresql-check-db-dir[13587]: Use “postgresql-setup --upgrade” to upgrade to version 9.4.
lug 03 12:02:04 localhost.localdomain postgresql-check-db-dir[13587]: See /usr/share/doc/postgresql/README.rpm-dist for more informatio
lug 03 12:02:04 localhost.localdomain systemd[1]: postgresql.service: control process exited, code=exited status=1
lug 03 12:02:04 localhost.localdomain systemd[1]: Failed to start PostgreSQL database server.
– Subject: L’unità postgresql.service è fallita
– Defined-By: systemd
– Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel

– L’unità postgresql.service è fallita.

– Il risultato è failed.
lug 03 12:02:04 localhost.localdomain systemd[1]: Unit postgresql.service entered failed state.
lug 03 12:02:04 localhost.localdomain systemd[1]: postgresql.service failed.
lug 03 12:02:04 localhost.localdomain audit[1]: pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s
lug 03 12:02:04 localhost.localdomain polkitd[841]: Unregistered Authentication Agent for unix-process:13581:890531 (system bus name :1
[/code]

PPS: Ho risolto facendo come indicato nel risultato sopra:

postgresql-setup --upgrade

e dopo aver riavviato questi sono i risultati:

[code][root@localhost luca]# systemctl status postgresql
● postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
Active: active (running) since ven 2015-07-03 12:10:23 CEST; 14min ago
Process: 1010 ExecStart=/usr/libexec/postgresql-ctl start -D ${PGDATA} -s -w -t 300 (code=exited, status=0/SUCCESS)
Process: 991 ExecStartPre=/usr/libexec/postgresql-check-db-dir %N (code=exited, status=0/SUCCESS)
Main PID: 1172 (postgres)
CGroup: /system.slice/postgresql.service
├─1172 /usr/bin/postgres -D /var/lib/pgsql/data
├─1310 postgres: logger process
├─1313 postgres: checkpointer process
├─1314 postgres: writer process
├─1315 postgres: wal writer process
├─1316 postgres: autovacuum launcher process
└─1317 postgres: stats collector process

lug 03 12:10:13 localhost.localdomain systemd[1]: Starting PostgreSQL databas…
lug 03 12:10:21 localhost.localdomain postgresql-ctl[1010]: LOG: redirezione…
lug 03 12:10:21 localhost.localdomain postgresql-ctl[1010]: SUGGERIMENTO: I …
lug 03 12:10:23 localhost.localdomain systemd[1]: Started PostgreSQL database…
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost luca]# journalctl -xe
lug 03 12:23:36 localhost.localdomain audit[2156]: pid=2156 uid=0 a
lug 03 12:23:36 localhost.localdomain audit[2156]: pid=2156 uid=0 a
lug 03 12:23:36 localhost.localdomain su[2156]: (to postgres) luca on pts/0
lug 03 12:23:36 localhost.localdomain su[2156]: pam_unix(su-l:session): session
lug 03 12:23:56 localhost.localdomain su[2156]: pam_unix(su-l:session): session
lug 03 12:23:56 localhost.localdomain audit[2156]: pid=2156 uid=0 a
lug 03 12:23:56 localhost.localdomain audit[2156]: pid=2156 uid=0 a
lug 03 12:24:39 localhost.localdomain systemd[1]: Starting Cleanup of Temporary
– Subject: L’unità systemd-tmpfiles-clean.service inizia la fase di avvio
– Defined-By: systemd
– Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel

– L’unità systemd-tmpfiles-clean.service ha iniziato la fase di avvio.
lug 03 12:24:40 localhost.localdomain systemd[1]: Started Cleanup of Temporary D
– Subject: L’unità systemd-tmpfiles-clean.service termina la fase di avvio
– Defined-By: systemd
– Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel

– L’unità systemd-tmpfiles-clean.service ha terminato la fase di avvio.

– La fase di avvio è done.
lug 03 12:24:40 localhost.localdomain audit[1]: pid=1 uid=0 auid=42
lug 03 12:24:40 localhost.localdomain audit[1]: pid=1 uid=0 auid=42
[/code]

Grazie a tutti.