I'm using DBeaver 5.0.5.
I created a database connection and setted it to "production" type.
When I run an application which does a drop table on this database,
I got something like this :
Query | 1568 | Waiting for table metadata lock | DROP TABLE meteo |
There aren't any other processes which use the table unless dbeaver.
Is that normal ?
If you've marked your connection as Production, then it most likely disabled auto-commit mode. You need to commit the open transaction (click the commit button on the toolbar).
If you're like me and you don't do a whole lot of scripting that requires transactions, I find it easier to enable auto-commit in the connection settings and toggle it off on the toolbar when I need transactions.
Related
Executing simple alter table add column hangs, this could be due to my application uses connection pooling which opens connections and probably locking tables. is there any way we can still execute alter table command in postgres while application is still running ?
Check the view pg_locks to see which concurrent transaction holds a lock the blocks the ALTER TABLE.
If your connection pool keeps connections hanging in the state “idle in transaction” (check pg_stat_activity), there is a bug in the connection pool or the application. You should fix that, because it causes other problems too, like table bloat because VACUUM cannot do its job.
A collection of statements to monitor locks is available in the Postgres Wiki:
https://wiki.postgresql.org/wiki/Lock_Monitoring
https://wiki.postgresql.org/wiki/Lock_dependency_information
In My University Management System i want to Perform Data Migration on Specific Day and so that i want close all open connections and Perform Data Migration as a Db admin user and after that Allow user to Establish connections to Database
after some Searching i find that script
To Disable MultiUser
alter database dbName set single_user with rollback immediate
To Enable MultiUser
alter database dbName set multi_user with rollback immediate
Question :
how to Perform my required Operation as a db admin?
it is a good way to do this or some better way ?
what does Disable Script doing?
what does Enable Script doing?
From this Disable Scriptall open connections will close ?
What you said is about the same what we do in this situation. The first statement puts the DB in "single_user" mode. That means, only YOUR current session is connected to the db after that statement. The "with rollback immidiate" option specifies that all open transaction and current queries and connections are closed and rolled back, so the database is in consistent state afterwards.
Personally, I dislike the "single_user" mode, because it allows any single user to connect if you accidentially close your connection. I'd use "restricted_user" instead. In that mode, only members of the db_owner fixed database role and dbcreator and sysadmin fixed server roles are allowed to connect to the database, but it does not limit their number. That will work better IF your users are not db_owner.
You second example just reverses that change and opens the DB to everyone ("multi_user") again.
As we know in Oracle no data or action query is committed until we call a commit. I want such implementation with SQL Server that I can run action queries on db but data is not changed permanently, it just let me see data before and after my action queries.
Or is there any way to mirror database on same server in such a way that I can test my queries on secondary database but it didn't have any impact on primary database.
You can use the IMPLICIT_TRANSACTIONS setting to achieve a similar function to what Oracle does:
Transactions that are automatically opened as the result of this setting being ON must be explicitly committed or rolled back by the user at the end of the transaction. Otherwise, the transaction and all of the data changes it contains are rolled back when the user disconnects.
You can, if you so choose, change a setting in Management Studio so that this setting is always in force when you open new query windows:
You can do it within same query window, in which you have written 'begin tran'
do not commit until not conform.
you can execute number of query within same window, which was give you your query preview before committing transaction.
It's only possible within same query window. you can not able view preview in other query window.
You can change your Isolation level from Read Committed to Snapshot to work around with your test queries.(If you dont want to see change in data during your transaction)
Please refer the below link for Snapshot Isolation level:
http://gavindraper.com/2012/02/18/sql-server-isolation-levels-by-example/
Our application has in-built functionality to update the database it uses (triggered when an app update is downloaded from our server.)
Usually, the update comprises of table and data conversion and then a drop of existing stored procedures and a create of all current stored procedures.
So we do the following from C#:
Create Connection
Set database to Single User Mode
Run upgrade script to upgrade tables and convert data
Run upgrade script to drop existing stored procedures and add new ones
Set database to Multi User Mode
Close connection
Step 2 -5 are done using the same connection. For some clients it occassionaly errors out in the middle of Step3 or Step 4. The log shows:
Error: Database 'MyDB' is already open and can only have one user at a time.
This is very strange because at that time we are already in Single User mode so no other user should be able to connect to the database, let alone somehow put it in Single User mode for its own connection.
We are wondering if some internal SQL Server process is taking over our Single User mode and preventing us from completing the update.
We are aware that if AUTO_UPDATE_STATISTICS_ASYNC is turned ON this may interrupt Single User Mode, but we have verified that it is turned off and it still occurred for the client.
Could a CHECKPOINT operation interrupt it? If so, what do we do about that, because that is a server-wide setting so we cannot modify it.
I need to keep synchronized a couple of databases, one is on sql 2000 and the other on 2005. The one on 2000 should be kept in read-only mode to make sure the users does not enter data. The 2005 is the one which are going to be updated by the users.
So I could develop a script to truncate and insert into the 2000 version with data from 2005 every night. My question is if there is some way to disable the read-only mode temporaly while the script is running. Is there a better approach?
Thanks,
You can disable the read-only mode while the script is running. You may also want to set RESTRICTED_USER to keep any users from accessing the database while processing.
I would tend along the response offered by Mike Henderson.
Essentially leverage db security to prevent users from modifying data and allow the account used to synchronize data to write.
Not sure what your time constraints are, but if you are relying on the db to be read-only to prevent end-users making changes, there is the possibility that they could get in during the time period that the db is in read/write mode.
Just for future reference, this is how I proceeded,
ALTER DATABASE MyDB SET READ_WRITE WITH ROLLBACK IMMEDIATE
ALTER DATABASE MyDB SET READ_ONLY WITH ROLLBACK IMMEDIATE
Thank you,