saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Install Salt from the Salt package repositories here:
https://docs.saltproject.io/salt/install-guide/en/latest/
Apache License 2.0
14.18k stars 5.48k forks source link

stopped PostgreSQL server leads to no errors #54471

Open srkunze opened 5 years ago

srkunze commented 5 years ago

Similar to #54470 and #54469

This time:

postgres@my-host:~> psql abc
psql: konnte nicht mit dem Server verbinden: Datei oder Verzeichnis nicht gefunden
    Läuft der Server lokal und akzeptiert er Verbindungen
    auf dem Unix-Domain-Socket »/var/run/postgresql/.s.PGSQL.5432«?

Output of salt is SUCCESS

          ID: abc__database_absent
    Function: postgres_database.absent
        Name: abc
      Result: True
     Comment: Database abc is not present, so it cannot be removed
     Started: 11:48:10.359703
    Duration: 5143.332 ms
     Changes:   

This should definitely lead to an error and a comment that the server is down.

xeacott commented 5 years ago

Hey @srkunze let's see if we can group all this information into a single ticket and identify what issues are going on with this module. I don't want to close tickets that identify issues and definitely don't want duplicates for sake of confusion.

xeacott commented 5 years ago

See https://github.com/saltstack/salt/issues/54470 and https://github.com/saltstack/salt/issues/54469

srkunze commented 5 years ago

Whatever you find is best. These tickets describe different situations, saltstack can be in. :-)

Also different salt states are concerned.

xeacott commented 4 years ago

Okay, thanks for clearing that up. I did re-read through them and see that they are for different outcomes but it appears that, in general, the error codes do need a bit more verbose information.

xeacott commented 4 years ago

I'll write this down to investigate this and the other related issues later this week, but I'll follow up Friday in either case to make sure we're on the same page about these 3 issues.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

sagetherage commented 4 years ago

not stale

stale[bot] commented 4 years ago

Thank you for updating this issue. It is no longer marked as stale.

srkunze commented 4 years ago

Alright another part of the issue to illustrate the behavior:

11:08:47 ----------
11:08:47           ID: database__ensure
11:08:47     Function: postgres_database.present
11:08:47         Name: mysystem
11:08:47       Result: True
11:08:47      Comment: Database mysystem is already present
11:08:47      Started: 11:08:32.564474
11:08:47     Duration: 81.264 ms
11:08:47      Changes:   
11:08:47 ----------
11:08:47           ID: database_absent
11:08:47     Function: postgres_database.absent
11:08:47         Name: mysystem
11:08:47       Result: True
11:08:47      Comment: Database mysystem is not present, so it cannot be removed
11:08:47      Started: 11:08:32.647191
11:08:47     Duration: 5185.282 ms
database__ensure:
  postgres_database.present:
    - name: {{ system.database }}

database_absent:
  postgres_database.absent:
    - name: {{ system.database }}
    - require:
      - database__ensure
postgres:~> dropdb mysystem
dropdb: Deletion of the database failed: ERROR:  database "mysystem" is being accessed by other users
DETAIL:  There is 1 other session using the database.
srkunze commented 4 years ago

Our current work-around according to https://dba.stackexchange.com/questions/11893/force-drop-db-while-others-may-be-connected

my_database_absent:
  cmd.run:
    - name: psql -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '{{ system.database }}'" && dropdb {{ system.database }}
    - runas: postgres
    - check_cmd:
      - "! psql {{ system.database }} -c ''"

In PostgreSQL 13 there will be: ''DROP DATABASE mydb FORCE"