0

I'm looking to implement postgresql with apache airflow, but first I need to install and set up a postgres database. I'm having a ton of trouble. I've tried many tutorials, like the following:

Link from the postgresql documentation: https://help.ubuntu.com/community/PostgreSQL

The last part of this article: https://www.statworx.com/de/blog/a-framework-to-automate-your-work-how-to-set-up-airflow/

Essentially, when I get to the second command of the first link, or anything where i use "psql" i get the following error:

psql: could not connect to server: Connection refused Is the server running on host "" and accepting TCP/IP connections on port 5432?

I've seen that you have to go into some directory and fix a setting but I don't seem to have the directory. All I need to do is set up a basic username and password with a simple db. I don't even know if the tutorials I'm looking at are the right ones to get me where I want to be - I have no experience with this.

Does anybody have any idea about this error, considering I can't find whatever directory people say to fix (maybe I don't have it because I didn't even begin to install this correctly)? Or a simpler step by step to getting this installed? I'm pretty lost.

adamSC
  • 101
  • 1
  • 1
  • 4
  • those two tutorials mention installing `postgresql-client` -- did you also install `postgresql`? Installing only the client will not get you rolling--you need to install the server too (or provide connection details to an existing database) – richyen Oct 21 '19 at 18:58
  • https://stackoverflow.com/q/32439167/905902 might help. NOTE: the error message asks you **two** questions: **1)** is the server running? **2)** is it listening on some port? – wildplasser Oct 21 '19 at 19:02
  • @richyen In the first link, I did try the part under "Installation", which is installing postgresql. But once I get to basic server setup and type the command 'sudo -u postgres psql postgres' I still get the psql error and im not sure why, since all I'm trying to do is set it up – adamSC Oct 21 '19 at 19:08
  • can you try `systemctl start postgresql` before doing `sudo -u postgres psql postgres`? – richyen Oct 21 '19 at 19:10
  • @wildplasser I do notice that. I'm thinking its because I'm trying to access a server that I never set up, but I'm struggling to figure out how to even get this far. – adamSC Oct 21 '19 at 19:10
  • @richyen when I try the first command, I get the following error: System has not been booted with systemd as init system (PID 1). Can't operate. What does this mean? – adamSC Oct 21 '19 at 19:13
  • You don't need systemd or initd to start postgres. Just `/etc/init.d/postgresql`. (plus the symlinks for the runlevels) – wildplasser Oct 21 '19 at 19:55
  • 1
    If you can't use `systemctl`, then maybe you can try `pg_ctl -D /etc/postgresql//data start`, then try `psql` again – richyen Oct 21 '19 at 20:45

1 Answers1

0

two questions:

  1. is the server running?

Unix_prompt> ps auxw| grep postgres .

Typical output:

postgres  1338  0.0  0.0 238136  8792 ?        S    okt12   0:42 /opt/postgres/bin/postmaster -D /data/db/postgres/pgdata  ### <<HERE
zzuser    1415  0.0  0.0  44488  1072 pts/31   S+   okt19   0:02 ssh postgres@10.224.60.103
postgres  1567  0.0  0.0  90964   532 ?        Ss   okt12   0:01 postgres: logger
postgres  1779  0.0  1.1 238496 138664 ?       Ss   okt12   0:25 postgres: checkpointer
postgres  1780  0.0  1.1 238320 138452 ?       Ss   okt12   1:12 postgres: background writer
postgres  1781  0.0  0.0 238136  4732 ?        Ss   okt12   0:49 postgres: walwriter
postgres  1782  0.0  0.1 238676 20972 ?        Ss   okt12   0:28 postgres: autovacuum launcher
postgres  1783  0.0  0.0  93332   880 ?        Ss   okt12   1:18 postgres: stats collector
postgres  1784  0.0  0.0 238544   988 ?        Ss   okt12   0:00 postgres: logical replication launcher
zzuser    3675  0.0  0.0  44160  1028 pts/26   S+   okt13   0:05 ssh postgres@192.168.0.102
zzuser   10541  0.0  0.0  44160   964 pts/29   S+   okt16   1:42 ssh postgres@192.168.0.102
  1. Is it listening om some port?

unix_prompt> netstat -ln | grep postgres

Typical output (snipped):

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 127.0.1.1:53            0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN  ## << HERE    
tcp        0      0 0.0.0.0:7               0.0.0.0:*               LISTEN     
tcp6       0      0 :::80                   :::*                    LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:631                 :::*                    LISTEN     
tcp6       0      0 :::5432                 :::*                    LISTEN  ## << HERE   
udp        0      0 0.0.0.0:5353            0.0.0.0:*                      
[snipped]                      
Active UNIX domain sockets (only servers)
Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ACC ]     STREAM     LISTENING     13402    /tmp/.s.PGSQL.5432  ## << HERE
[snipped]

If the first list is (almost) empty, your server is not running. (or did not start) If the sevond list does not contain port#5432, it is not listening. That's all.

wildplasser
  • 43,142
  • 8
  • 66
  • 109
  • when I run the first command the only output is: `adamdill 45 0.0 0.0 14804 1192 tty1 S 09:40 0:00 grep --color=auto postgres` which I'm guessing means nothing is running but thats not suprising. I'm just trying to figure out how to get it up an running in the first place. – adamSC Oct 22 '19 at 16:47
  • I've read that you can edit a file called postgresql.conf to change settings around and such, but I don't seem to have this file. – adamSC Oct 22 '19 at 16:54
  • Well, maybe you don't have a running server, then. (step#1) – wildplasser Oct 22 '19 at 21:27
  • How do I go about doing that? Sorry, I'm definitely a beginner. – adamSC Oct 24 '19 at 16:42