How to delete a table in postgresql - sql

There is a postgresql installation on my server that worked fine so far. However now there is a single table (all other tables work fine) which I cannot open through pgadmin3 or drop.
I've tried restarting the server. Didn't help. I also tried dropping the table with DROP TABLE from the command line on the server. It's just stuck. I've executed the command and it has been just hanging in the console for the past hour.
I don't know what to do. Is there a file I could erase in the data directory perhaps?

Most probably explanation: some other open transaction is holding an exclusive lock on the table.
You are using pgAdmin, so you can check with Tools -> Server Status. The activity pane lists all current connections. For instance, there is one (or more) listings for every open SQL window. Look for long running connections.
You can also try to issue a DROP TABLE and check this list. With any luck you'll see what blocks it. Once you have identified the troublemaker and made sure, it's not needed, you might be able to kill the process. Might be vacuuming gone haywire because of bad settings ..
That, or something is seriously broken.

You could try taking a dump of the database and see if that works? Also have a look at the http://www.postgresql.org/docs/9.1/static/runtime-config-logging.html#GUC-CLIENT-MIN-MESSAGES and log_min_messages options. Change that to debug and see what is happening when you try to drop the table.

In Case of Windows Users. Try restarting Postgresql by follwowing these steps: Start -> Run -> (then type in:) services.msc. Select Local postgresql Server and then press "Restart." Now, go ahead and try deleting the database or the table you wanted to delete (Via pgAdmin). Hope it helps.

Related

SQL (Find & Replace) Entire Database

I am using PHPMYADMIN from SiteGround CPanel.
Story: I had Cloudflare setup for a php platform, I then realised it was causing issues so I removed it. The issue I'm left with is that half of my site is still running of (https://www.example.com).
What I have done so far: In the config files of my script I have already set it so that it runs through https alone.
What I want to achieve: I noticed in the database that there are some fields that are running through the www. I want to execute a command that will automatically find anything with my old domain (https://www.example.com) and replace it with (https://example.com). I noticed that the fields are not all appearing from a single column/file, it is all over the place, so a field&replace overall should fix the issue.
I would appecaite any help. Since it is database I don't wish to try out random things from different websites provding their feedback. I was recommended to use this website for assistance (if possible).
Thank you in advance.
Probably the most straightforward and quickest way, is to simply take a dump of the entire database, open the sql dump file in some text editor, and then do a text replace from [old url] to [new url]. Then import the dump file back to the database. This should work just fine and avoid the headache of uncertainty and risk over doing a write operation on the entire database's tables via some db query.

Can I undo the last few transaction, or revert to yesterday in MariaDB?

I have an SQL file containing several commands, when I need to make a correction to my application database that the application can't yet do, I use DBVis to select and execute the command I need (e.g. to delete an incorrect entry). Problem is, the button to run the whole page is right next to the button to run a selected command. So I just dropped and re-created my table, losing all my data. Is there a way to undo this?
I'm looking to either 'undo' each command until I get back to the right place, or revert back to yesterday, where I know everything was correct.
Thanks!
Yes, you can if...
your administration tool did set autocommit=OFF by default, you can
just execute a ROLLBACK (or just shutdown your administration tool)
If latter doesn't work, check if your binary log was enabled, and restore with mysqlbin log tool
If none of the above mentioned solution works, use your (probably not existent) backup for restoring

I see deleted records in Spring with JDBC

I have a webapp with Spring. I connect to the DB via JDBC. My issue comes in the following workflow:
I insert some testing record to the DB with the app. I see in the app and in SQLDeveloper (same query) that the record gets inserted. No problem.
I delete that record from SQLDeveloper. I see in SQLDeveloper that the record gets deleted. No problem
I go back to the webapp and refresh the page. Problem: the deleted records are still there!.
I'm sure I'm using the same query in the app and in SQLDeveloper (this is the only instance when I don't see the same in both environments). I tried restarting the app, but I can't imagine what else to do. Is there any cache system in Spring that could be causing this?
I can post some code if it would be any help, though I doubt it...
I suspect that you haven't committed the result of your deletion in SQLDeveloper, so you see your deletion in SQLDeveloper (same transaction), but not anywhere else, because those are running in different transactions.
EDIT: To commit, you can just execute the command commit; in SQLDeveloper, or hit the commit button at the top of the query window (a DB icon with a green tick in front of it)

Toad: Table Autocomplete Functionality Not Working

I've been using Toad for more than a year now without problems. All of a sudden the table autocomplete feature has ceased working. No settings have been changed, and I've clean installed a new TOAD version, yet the problem persists.
The image below shows autocomplete defaulting into view IN_INSTRUMENT in schema MCDM. Normal behaviour should result in a table/view list.
It is notable that the above does not happen with all schemas. For some schemas I will still see a table list. In the beginning this error happened only with a single schema. Now it is slowly progressing to other schemas as well, which is exceptionally frustrtating when you're dealing with dozens of schemas that contain hundreds of tables each. It slows down development when you must open Schema Browser and look for the exact table/view/procedure/package each time instead of letting autocomplete give suggestions.
This same issue has been described in this thread and and this thread with less detail, yet no accepted answer has been given.
As can be seen from Code Assist settings, these should be in order.
How to reset autocomplete behaviour into what is its original state?
Under View > Toad Options > Editor > Code Assist > Toad Insight Objects, checking Synonyms (in addition to Public Synonyms) worked for me.
I've found the solution to this problem. The issue was a corrupt configuration file. For anyone else with the same problem, this is how I fixed mine:
Backup your appdata folder - you can find its location in options -> general -> application data.
Create a new set of user files using Utilities -> Copy User Settings -> Create clean set of user files. Make sure you are running Toad with administrator rights.
Note that the above will delete all your saved connection details (schema names, passwords, connection strings), so take a note of these.
Hope this helps someone in the future.
Try to check "Public synonyms" in the "Toad insight objects".
Go to Toad Options, and then Editor > Code Assist and uncheck "Cache Code Insight results". This made it immediately start working for me using Toad for Oracle version 9.7. I could then go back and check the box and it would still work.
I faced the same problem even though I set up everything mentioned above.
So basically Toad does not suggest column names if I don't define the scheme name.
X(schema).TABLE_NAME.(then lists all columns)
Worked for me..

Replace/Rename the Online Database

I have got a database of ms-sql server 2005 named mydb, which is being accessed by 7 applications from different location.
i have created its copy named mydbNew and tuned it by applying primary keys, indexes and changing queries in stored procedure.
now i wants to replace old db "mydb" from new db "mydbnew"
please tell me what is the best approach to do it. i though to do changes in web.config but all those application accessing it are not accessible to me, cant go for it.
please provide me experts opinion, so that i can do replace database in minimum time without affecting other db and all its application.
my meaning of saying replace old db by new db is that i wants to rename old db "mydb" to "mydbold" and then wants to remname my new db "mydbnew" to "mydb"
thanks
Your plan will work but it does carry a high risk, especially since I'm assuming this is a system that has users actively changing data, which means your copy won't have the same level of updated content in it unless you do a cut right before go-live. Your best bet is to migrate your changes carefully into the live system during a low traffic / maintenance period and extensively test it once your done. Prior to doing this, or the method you mentioned previously, backup everything.
All of the changes you described above can be made to an online database without the need to actually bring it down. However, some of those activities will change the way in which the data is affected by certain actions (changes to stored procs), that means that during the transition the behaviour of the system or systems may be unpredicatable and therefore you should either complete this update at a low point in day to day operations or take it down for a maintenance window.
Sql Server comes with a function to make a script file out of you database, you can also do this manually but clicking on the object you want to script and selecting the Script -> CREATE option. Depending on the amount of changes you have to make it may be worthwhile to script your whole new database (By clicking on the new database and selecting Tasks -> Generate Scripts... and selecting the items needed).
If you want to just script out the new things you need to add individually then you simply click on the object you want to script, select the Script <object> as -> then select DROP and CREATE to if you want to kill the original version (like replacing a stored proc) or select CREATE to if your adding new stuff.
Once you have all the things you want to add/update as a script your then ready to execute that against the new database. This would be the part where you backup everything. Once your happy everything is backed up and the system is in maintenance or a low traqffic period, you execute the script. There may be a few problems when you do this, you will need to fix these as quickly as possible (usually mostly just 'already exisits' errors, thats why drop and create scripts are good) and if anything goes really wrong restore your backups and try again (after figuring out what happened and how to fix it).
Make no mistake if you have a lot of changes to make this could be a long process, or it could take mere minutes, you just need to adapt if things go wrong and be sure to cover yourself with backups/extensive prayer. Good Luck!