Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YlysQ-0001y4-I4 for pgsql-admin@arkaria.postgresql.org; Sat, 25 Apr 2015 12:08:06 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YlysQ-0002Bx-2K for pgsql-admin@arkaria.postgresql.org; Sat, 25 Apr 2015 12:08:06 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YlysP-0002Bn-Bf for pgsql-admin@postgresql.org; Sat, 25 Apr 2015 12:08:05 +0000 Received: from mout.gmx.net ([212.227.15.19]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YlysK-00055X-IH for pgsql-admin@postgresql.org; Sat, 25 Apr 2015 12:08:03 +0000 Received: from [192.168.1.10] ([88.130.55.206]) by mail.gmx.com (mrgmx001) with ESMTPSA (Nemesis) id 0LdpcB-1ZBRny1tFj-00iyb7 for ; Sat, 25 Apr 2015 14:07:57 +0200 Message-ID: <553B839F.2040503@gmx.net> Date: Sat, 25 Apr 2015 14:07:59 +0200 From: Andreas User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: pgsql-admin@postgresql.org Subject: How to drop automatically some databases? Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:oMcQYxH0InwIhMfJanMast+IAGNHtAKIl/kY9fg3rBxzDM3xzO7 jbeuTVvsiwOZTN+PZZIAYItuGPnOz4dY+k//wM0dMnDYY8itCmTseUK4Zo/9aqYkbGzeQiQ dRZAGIWBz9GVf7JEDpsjub+mFcmSVQNfDSiQYzV7DZmLAzGgxcU8XA+z61WEE/xXLMGkl6E dhT/Wb8eX3NQ3ATxSM7QQ== X-UI-Out-Filterresults: notjunk:1; X-Pg-Spam-Score: -2.1 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-admin Precedence: bulk Sender: pgsql-admin-owner@postgresql.org I've got a developer PC (Windows) that hosts copies of a production database so I can tinker with it without causing damage to the production database. Every night a script fetches a dump of the production database. Then it renames the test-db on my PC, creates a new test-db and imports the dump. The current version is named "db_test". The older copies are named "db_test_yymmdd_hhmm". The name is extended with the timestamp of the import. Now I'd like to keep just 3 older copies in case I want to look up structural moifications I've made the day before. Older copies should get dropped. This would show the names to drop. select datname from ( select datname from pg_database where datname ilike 'db_test_%' order by datname ) as x EXCEPT select datname from ( select datname from pg_database where datname ilike 'db_test_%' order by datname desc limit 3 ) as y; I tried to run this drop database ( ... the select above ... ) in the DB "postgres" but it didn't work. After a couple of seconds I get a syntax error. What now? :} -- Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-admin