PostgreSQL server query execution - sql

I'm using PostgreSQL server and there's the thing I need to know about query execution on it. I have two different clients connected to the server simultaneously. Now, the clients are executing some queries at the same time. Is it true that any clien't query will be exectueted in a separated thread?
Or the server can split the query excution into multiple threads for optimization's sakes.

Related

How to timeout a large SQL query in R

I have a SQL query I'm running in RODBC. Some of the parameters are user defined and there is a risk of running a huge SQL query.
I'd like to detect and stop any SQL queries that run over a certain amount of time.
I've looked at R.utils but it doesn't seem to time out:
R.utils::withTimeout({sqlQuery(ch, sql)}, timeout = 1.08)

Query single server in SQL server group

I have 3 databases hosted across 3 different servers, all of which have different data and structures. I need to perform a query that will draw data from various tables across all three of them.
I've registered the three servers into a server group, and I've confirmed that all of the connections are working properly.
Here's an example of the problem I'm facing. For the first part of this query, I need to retrieve a list of records from the 'Applications' table in DB1 so I write:
SELECT * FROM [DB1].[dbo].[Application]
I know that this query works partially because it starts returning results from the correct table. The problem is that I haven't specified the server that DB1 is on, so once the query has finished querying DB1.dbo.Application, it looks for the same database and table on the next server. The database and table don't exist on the other servers so the query fails.
So how do I specify the server that I want the query to run on? I've tried [server_name].[DB1].[dbo].[Application], but it still runs the query across all of them.
Server groups are for maintenance purposes, what you need to use is a linked server
On one of the servers, say SERVER1, you will need to set up two linked servers - one to SERVER2 and one to SERVER3
From SERVER1 you will then be able to query the other servers using the four part name in a normal query window:
SELECT * FROM DatabaseName.dbo.Table1;
SELECT * FROM SERVER2.DatabaseName.dbo.Table2;
SELECT * FROM SERVER3.DatabaseName.dbo.Table3;
You can also use the tables from the remote server in JOINs etc as though they were on the local server and the remote servers don't even need to run SQL Server - they can be Oracle, MYSQL etc.
Be aware though, remote servers are slow and you may struggle with large datasets

the transaction log for database 'tempdb' is full due to 'ACTIVE_TRANSACTION

I'm running same query in two different windows of the same server.
the only difference is : the query that is throwing above error has got 'index' on the temporary tables.
The query w/o index on temporary tables is working fine. Please explain how could index be a reason for this error?
This depends from your query. SQL-Server has to maintain indexes during data changes. This can drives you in different time-waith events.
Try this: check on your two different SQL Server instances what's heppening exactly to your running session during query executon.
You can do this monitoring wait events creating a monitor sessions for a single SPID.
This is my complete procedure to this: http://zaboilab.com/sql-server-toolbox/monitoring-wait-events-of-a-single-session-or-query

Talend's tOracleInput does not read data

My colleague created a project in Talend to read data from Oracle database.
I used his project and so I have his Job context with connection parameters to Oracle DB and Talend successfully connects on that computer.
I've created a trivial job which is composed of two components: tOracleInput which should be reading data and tLogRow which should be redirecting output to Talend's terminal.
The problem is that when I start the job - data is not outputted to terminal and instead of row amount outputted per second I see Starting ... status.
Would it be connection issues, inappropriate java version on my computer or something else?
Starting... status means that the query is being executed. Usually it takes a few seconds to execute a simple query against the database. This is because of the Oracle database behavior that it starts to return the data without completing a full table scan. To use this feature you can use joins and filters, but not group by / order by.
On the other hand if you're using a view or executing a complex query, or just simply use DISTINCT it could happen that the query execution takes a few minutes. This is because the oracle database generates the ResultSet on the database side before returning the records.

Multiple Sql Server instances on same machine - cross query performance

I have 1 SQL server machine having 2 instances [Instance1] and [Instance2]
If I need to execute a cross query joining tables like below
[Instance1].[db1].[dbo].[table1]
joins
[Instance2].[db2].[dbo].[table2]
Will there be lot of performance hit in above query compared to if both databases are in same instance?
Please note that both instances are in same machine (server).
Thanks for help!