saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:
https://repo.saltproject.io/
Apache License 2.0
14.13k stars 5.47k forks source link

states.postgresql_database.absent reports DB in use as "not present" #37506

Open eliasp opened 7 years ago

eliasp commented 7 years ago

Description of Issue/Question

When trying to remove a DB which is in use using postgresql_database.absent the resulting error message wrongly indicates the DB wouldn't be present instead of it being "in use".

Setup

Make sure to have a PostgreSQL DB setup and in use.

Steps to Reproduce Issue

Try to remove an existing (and used) PostgreSQL DB using: salt-call --local state.single postgres_database.absent name=test_api_38c0f0cb

The log output clearly shows the discrepancy between what's actually happening (ERROR: database "test_api_38c0f0cb" is being accessed by other users) and what Salt is reporting (Database test_api_38c0f0cb is not present, so it cannot be removed):

# salt-call --local state.single postgres_database.absent name=test_api_38c0f0cb
[INFO    ] Loading fresh modules for state activity
[INFO    ] Running state [test_api_38c0f0cb] at time 07:58:12.303656
[INFO    ] Executing state postgres_database.absent for test_api_38c0f0cb
[INFO    ] Executing command ['/usr/bin/psql', '--no-align', '--no-readline', '--no-psqlrc', '--no-password', '--dbname', 'postgres', '-v', 'datestyle=ISO,MDY', '-c', 'COPY (SELECT datname as "Name", pga.rolname as "Owner", pg_encoding_to_char(encoding) as "Encoding", datcollate as "Collate", datctype as "Ctype", datacl as "Access privileges", spcname as "Tablespace" FROM pg_database pgd, pg_roles pga, pg_tablespace pgts WHERE pga.oid = pgd.datdba AND pgts.oid = pgd.dattablespace) TO STDOUT WITH CSV HEADER'] as user 'postgres' in directory '/var/lib/postgresql'
[INFO    ] Executing command ['/usr/bin/psql', '--no-align', '--no-readline', '--no-psqlrc', '--no-password', '--dbname', 'postgres', '-c', 'DROP DATABASE "test_api_38c0f0cb"'] as user 'postgres' in directory '/var/lib/postgresql'
[ERROR   ] Command '['/usr/bin/psql', '--no-align', '--no-readline', '--no-psqlrc', '--no-password', '--dbname', 'postgres', '-c', 'DROP DATABASE "test_api_38c0f0cb"']' failed with return code: 1
[ERROR   ] stderr: ERROR:  database "test_api_38c0f0cb" is being accessed by other users
DETAIL:  There are 2 other sessions using the database.
[ERROR   ] retcode: 1
[ERROR   ] Error connecting to Postgresql server
[INFO    ] Database test_api_38c0f0cb is not present, so it cannot be removed
[INFO    ] Completed state [test_api_38c0f0cb] at time 07:58:17.479731 duration_in_ms=5176.075
local:
----------
          ID: test_api_38c0f0cb
    Function: postgres_database.absent
      Result: True
     Comment: Database test_api_38c0f0cb is not present, so it cannot be removed
     Started: 07:58:12.303656
    Duration: 5176.075 ms
     Changes:   

Summary for local
------------
Succeeded: 1
Failed:    0
------------
Total states run:     1
Total run time:   5.176 s

Versions Report

    Salt Version:
               Salt: 2016.3.4

    Dependency Versions:
               cffi: Not Installed
           cherrypy: Not Installed
           dateutil: 2.2
              gitdb: Not Installed
          gitpython: Not Installed
              ioflo: Not Installed
             Jinja2: 2.7.3
            libgit2: Not Installed
            libnacl: Not Installed
           M2Crypto: Not Installed
               Mako: Not Installed
       msgpack-pure: Not Installed
     msgpack-python: 0.4.2
       mysql-python: 1.2.3
          pycparser: Not Installed
           pycrypto: 2.6.1
             pygit2: Not Installed
             Python: 2.7.9 (default, Jun 29 2016, 13:08:31)
       python-gnupg: Not Installed
             PyYAML: 3.11
              PyZMQ: 14.4.0
               RAET: Not Installed
              smmap: Not Installed
            timelib: Not Installed
            Tornado: 4.2.1
                ZMQ: 4.0.5

    System Versions:
               dist: debian 8.6 
            machine: x86_64
            release: 3.16.0-4-amd64
             system: Linux
            version: debian 8.6 
Ch3LL commented 7 years ago

@eliasp looks like we need to improve the error reporting. Thanks we will need to get this fixed up

eliasp commented 7 years ago

@rallytime please re-open this issue - I don't have permission to do so.

It looks like this was mis-referenced in #37623 and 369653c which has nothing to do with this issue.

rallytime commented 7 years ago

Sorry about that @eliasp!

msummers42 commented 7 years ago

This is basically a duplicate of https://github.com/saltstack/salt/issues/33037 for what it's worth.

stale[bot] commented 6 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.

breshead commented 4 years ago

This is still an issue. Would like to see it fixed..

stale[bot] commented 4 years ago

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