BeginBinaryImport in a transaction - postgresql

As far as I can tell, the COPY command in Postgres supports transactions, but I don't see a way to specify a transaction with NpgsqlConnection.BeginBinaryImport. Is it not supported?

BeginBinaryImport implicitly participates in a transaction started before it. So just do NpgsqlConnection.BeginTransaction first, and then call BeginBinaryImport.

Related

KPI for retryRead and retryWrite

With mongo 4.2, mongoDB support retryWrites and retryReads. But do we have any KPI/statistics to know how many such retryWrites/reads happend? Also may I know is the retry applicable only if we use transaction
do we have any KPI/statistics to know how many such retryWrites/reads happend
one retry attempt for failed operation and only for exception that are considered retryable. Effectively all meaningful for user exceptions are retryable though.
Also may I know is the retry applicable only if we use transaction
no, it's not related to transactions

Extended events not capturing Entity Framework queries (read/updates)

I had added the Extended event to track sql calls which is slowing down my system leading to Timeout exceptions and other
CREATE EVENT SESSION [longrunning_statements] ON SERVER
ADD EVENT sqlserver.sql_statement_completed(
WHERE ([duration]>(2000000) AND [database_id]=(9)))
ADD TARGET package0.event_file(SET filename=N'c:\capture\xe_longrunning_statement.xel',metadatafile=N'c:\capture\xe_longrunning_statement.xem')
WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,MAX_DISPATCH_LATENCY=30 SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=OFF,STARTUP_STATE=OFF)
GO
But i noticed it does not register sql server updates/read queries/procedures calls from Entity Framework but only logged my sql queries run using SSMS.
Any ideas are appreciated
UPDATE:
I use EF6.1 which used i think batches to save data.
Instead of trying to capture sqlserver.sql_statement_completed I would capture sqlserver.sql_batch_completed and sqlserver.rpc_completed for application/API issued queries/stored procedures.
If that does not work then removing the filters(or at least the duration filter (as Andrey is suggesting in the comments) would probably give us more insight on why the queries are not being captured.

AsyncQuery with postgresql and dapper using npqsql

I was trying dapper orm and recently they added asyncquery support. I googled it about that. It is wonderful if you have heavy traffic on your site. I was trying that with postgressql and dapper. Now, in connection if I am passing simple connection string it works fine. But as per couple of articles it is not true async if I want to use it, I need async connection string.
Now, I don't know how to use with Postgresql and npgsql. Here is complete article for reference where author explains how to do it with Sql Server.
What I need to do if I want same with Postgresql?
Please let me know if any further requirement needed.
The author of this article is somewhat wrong - in .NET 4.5 the AsynchronousProcessing property is ignored because it is no longer required. You can just start calling the Async methods of SqlClient without any special connection strings.
Whether the operations will execute asynchronously, depends on the database provider. For example, the default implementation of DbCommand.ExecuteDbDataReaderAsync actually executes synchronously and blocks the calling thread. SqlCommand overrides this method and executes asynchronously.
Unfortunately, NpgsqlCommand doesn't override this method so you are left with synchronous execution only.

How To:Transaction Rollback in squeryl

Can anybody please tell me how to handle a transaction rollback in squeryl explicitly?
And also how can we add or remove columns in squeryl dynamically?
Thanx...
Just to elaborate a bit on the response from #didierd. There is one Session/Connection bound to each transaction. You can access the current Session, and thereby the Connection with code like:
Session.currentSession.connection
Or, if you're not sure if you're within a transaction
Session.currentSessionOption map {_.connection}
If you do roll back the transaction this way it will be your responsibility to start a new one or make sure there is no further use of the connection, so use with care.
You have an access to the JDBC's java.sql.Connection (connection in Session), so if you really cannot use transaction / inTransaction, you can call rollback there.
With access to the connection, you can also execute arbitrary SQL requests and so change the database schema, but be mindful that your squeryl-using code has a static, compile time known schema.

continue insert when exception is raised in postgres

HI,
Iam trying to insert batch of records at a time when any of the record fails to insert i need to trap that record and log that to my failed record maintanance table and then the insert should continue. Kindly help on how to do this.
If using a Spring or EJB container there is a simple trick which works very well : provide a LogService witn a logWarning(String message) method. The method must be annotated/configured with the REQUIRES_NEW transaction setting.
If not then you'll have to simulate it using API calls. Open a different connection for the logging, when you enter the method begin the transaction, before leaving commit the transaction.
When not using transactions for the insert, there is actually nothing special you need to do, as by default most database run in autocommit and commit after every statement.