Django app/postgres don't respond after running Snapshot!?

October 8, 2014 4.2k views

I made a Snapshot yesterday of a Django app running on a development server. I made sure to run sudo poweroff before the Power Cycle.

After the App restarted, I couldn’t access the domain in my browser. I then try to dump my database, but I get the following error:

pg_dump: [archiver (db)] connection to database "db" failed: could not connect to server: Connection refused
    Is the server running on host "####" and accepting
    TCP/IP connections on port ###?

It actually seems like I can’t get any response from the DB or the app.

Response from nmap ip##
Host is up (0.00012s latency).
PORT STATE SERVICE
80/tcp closed http

But the logs from the Django app tell me that it should be running.
How do I retrieve the data from my database and get the app running again?

Thank you!

6 comments
  • Have you attempted to restart your postgres after you encountered this issue? These messages would appear to indicate that the database is not currently running

    sudo service postgresql restart
    
  • I get the same error after restarting postgresql

  • Is Postgres running? What’s the output of

    sudo ps wwaux | grep postgres
    
  • Yes it seems to be running. I get the following output.

    root       588  0.0  0.2  46628  1392 ?        S    12:38   0:00 su postgres sh -c /usr/lib/postgresql/9.3/bin/postgres           -D  /var/lib/postgresql/9.3/main  -c config_file=/etc/postgresql/9.3/main/postgresql.conf  -c listen_addresses=*
    message+   589  0.0  3.1 244852 16036 ?        Ss   12:38   0:00 /usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/9.3/main -c config_file=/etc/postgresql/9.3/main/postgresql.conf -c listen_addresses=*
    message+   591  0.0  0.3 244852  1860 ?        Ss   12:38   0:00 postgres: checkpointer process                                                                                                                    
    message+   592  0.0  0.5 244852  2660 ?        Ss   12:38   0:00 postgres: writer process                                                                                                                          
    message+   593  0.0  0.3 244852  1648 ?        Ss   12:38   0:00 postgres: wal writer process                                                                                                                      
    message+   594  0.0  0.5 245704  2976 ?        Ss   12:38   0:00 postgres: autovacuum launcher process                                                                                                             
    message+   595  0.0  0.3 100672  1760 ?        Ss   12:38   0:00 postgres: stats collector process                                                                                                                 
    root      2251  0.0  0.1  11748   900 pts/0    S+   13:35   0:00 grep --color=auto postgres
    postgres 32480  0.0  3.0 247716 15504 ?        S    12:18   0:00 /usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/9.3/main -c config_file=/etc/postgresql/9.3/main/postgresql.conf
    postgres 32482  0.0  0.3 247716  1872 ?        Ss   12:18   0:00 postgres: checkpointer process                                                                                              
    postgres 32483  0.0  0.5 247716  2676 ?        Ss   12:18   0:00 postgres: writer process                                                                                                    
    postgres 32484  0.0  0.3 247716  1660 ?        Ss   12:18   0:00 postgres: wal writer process                                                                                                
    postgres 32485  0.0  0.5 248576  2972 ?        Ss   12:18   0:00 postgres: autovacuum launcher process                                                                                       
    postgres 32486  0.0  0.3 103524  1788 ?        Ss   12:18   0:00 postgres: stats collector process 
    
  • I tried running the script from this forum: https://coderwall.com/p/wtqlca

    Which restarted my app properly. However, my database name is different from the app name I’m using, so a new database container was created, which is obviously empty.

    I’m not sure if dokku postgresql:create original_db_name is going to erase my original database, or just restart the container.

  • Show 1 more comments
1 Answer

Hi!

So it sounds like you are using the Dokku postgres plugin. If that’s the case, then to dump a database, you’ll need to do it with Dokku as it is running inside a container.

dokku postgresql:dump dbname > foo.sql

and to restore one:

dokku postgresql:restore dbname < foo.sql

As to the question of will dokku postgresql:create original_db_name will destroy the old one, looking at the code:

    if [[ -f "$DOKKU_ROOT/.postgresql/volume_$APP" ]]; then
        VOLUME="`cat $DOKKU_ROOT/.postgresql/volume_$APP`:/opt/postgresql"
        echo
        echo "-----> Reusing postgresql/$APP database"
    else
        VOLUME="/opt/postgresql"
        # Generate a random password for DB user
        DB_PASSWORD=$(< /dev/urandom tr -dc A-Za-z0-9 | head -c 16)
        echo $DB_PASSWORD > "$DOKKU_ROOT/.postgresql/pwd_$APP"
        chown dokku: "$DOKKU_ROOT/.postgresql/pwd_$APP"
        chmod 700 "$DOKKU_ROOT/.postgresql/pwd_$APP"
    fi

it looks like it will attempt to reuse the persistent volume.

Have another answer? Share your knowledge.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!