August 19th, 2013, 02:59 PM
Drop database noob
created a user pgsql_admin, created xxxxxxdb as that user. now i want to delete it. hate to ask but how's it done?
i've logged in as the user and ran "dropdb xxxxxxdb" logged in as postgres and ran "drobdb xxxxxxdb".
logged in as postgres and ran DROP DATABASE [IF EXISTS] xxxxxxdb.
I've the PostSQL 9.1.9 documentation DROP DATABASE open in front of me right now. I've googled for it, and I've searched this forum and came up with this hit.
But when I run '\l" the database is listed.
Running Wheezy for the o/s.
August 20th, 2013, 12:51 AM
From within psql:
Caveat: you cannot be connected to that database at the moment.
drop database [db_name];
The psql prompt shows what db you're currently connected to. Check this out:
So when I was connected to the database "foo" the prompt was "foo=#", and I couldn't drop the database named "foo" right then because I had an open connection to it, but I could drop "bar", because it was not then in use. When I switched my connection to my default database "ceverett" I was then able to drop foo with no issue.
[ceverett@taco ~]$ psql
Type "help" for help.
ceverett=# create database foo;
ceverett=# create database bar;
ceverett=# \c foo;
You are now connected to database "foo" as user "ceverett".
foo=# drop database foo;
ERROR: cannot drop the currently open database
foo=# drop database bar;
foo=# \c ceverett
You are now connected to database "ceverett" as user "ceverett".
ceverett=# drop database foo;
If your database name has special capitalization or spaces or anything else (silly) in it like "MyDataBase" or "My Database" whatever you'll need to put double quotes around the name.
Comments on this post
August 20th, 2013, 03:01 PM
The semi colon did the trick. Thanks for helping me out it was driving me crazy,LOL. Looking at the documentation it seemed simple. But the doc's don't mention the semi colon and for greenhorns that's a pita. And thanks for the detailed information I appreciate you taking the time to school me.
Originally Posted by zxq9
August 20th, 2013, 04:26 PM
Yes it does, right at the beginning where the SQL syntax is explained:
Originally Posted by jim_armstrong
Taken from: http://www.postgresql.org/docs/curre...x-lexical.html
Originally Posted by The Manual
(And besides: this is also one of the most basic SQL syntax rules).
I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags.
Tips on how to ask better questions:
August 21st, 2013, 06:50 PM
Here's the link I'm referring too. No mention of the semi colon here.
Originally Posted by shammat
I didn't say I knew jack about SQL. Should I be doing this probably not. But I'm stuck with it. Someone else left in the middle of the project.
I'll check out the link you provided