Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute queries with NOLOCK on MS SQL side #200

Closed
kloba opened this issue Mar 11, 2019 · 3 comments
Closed

Execute queries with NOLOCK on MS SQL side #200

kloba opened this issue Mar 11, 2019 · 3 comments

Comments

@kloba
Copy link

kloba commented Mar 11, 2019

Hello,

How to run all queries throughout tds_fdw in NOLOCK mode on MS SQL side?

I need this, in a case to don't lock a table on an OLTP database.

Best regards,
Taras Kloba

@SudoerWithAnOpinion
Copy link
Contributor

Use the query option in the foreign table definition and define your query WITH NOLOCK

CREATE FOREIGN TABLE mssql_table (
	id integer,
	data varchar)
	SERVER mssql_svr
	OPTIONS ( query 'SELECT * FROM dbo.mytable WITH (NOLOCK)' );

Keep in mind, this causes READ UNCOMMITED (or dirty reads) and is generally considered bad practice. The MSSQL lock manger should allow your query to read data without locking the data from other transactions and updates (since this is a non-blocking type of lock) unless an UPDATE needs an exclusive lock for some reason.
Due to the issues that arise from dirty reads, you might be returning more data (or incomplete/ or duplicated data) back to postgres. Use this option with care.

@SudoerWithAnOpinion
Copy link
Contributor

@kloba: If this resolved your issue, can you be a sweetie and close this issue?
@GeoffMontee: I think this has gone stale, can you close this if @kloba does not reply?

@kloba
Copy link
Author

kloba commented Oct 21, 2019

Thank you a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants