Why do I get an open transaction when just selecting from a database View?

前端 未结 6 1064
一个人的身影
一个人的身影 2021-01-02 11:17

If I execute a simple select statement in pl/sql developer against a database table, I get a standard set of results back as I would expect.

Recently, I pasted a que

6条回答
  •  暖寄归人
    2021-01-02 11:49

    TLDR : On select from remote database you also create session and connection for remote DB. That session and connection persists as long as local user session. As you can guess this can lead to some problems with keeping up with session and connections.

    SO ALWAYS DO A COMMIT : SELECT * FROM emp@sales; COMMIT;

    I like a long read section :

    This was bugging me also so much why there is an transaction on selects from db_links and decided to finally end this so from oracle documentation :

    Oracle® Database Administrator's Guide 11g Release 2 (11.2) https://docs.oracle.com/html/E25494_01/ds_appdev002.htm

    Controlling Connections Established by Database Links When a global object name is referenced in a SQL statement or remote procedure call, database links establish a connection to a session in the remote database on behalf of the local user. The remote connection and session are only created if the connection has not already been established previously for the local user session.

    The connections and sessions established to remote databases persist for the duration of the local user's session, unless the application or user explicitly terminates them. Note that when you issue a SELECT statement across a database link, a transaction lock is placed on the undo segments. To rerelease the segment, you must issue a COMMIT or ROLLBACK statement.

    Terminating remote connections established using database links is useful for disconnecting high cost connections that are no longer required by the application. You can terminate a remote connection and session using the ALTER SESSION statement with the CLOSE DATABASE LINK clause. For example, assume you issue the following transactions:

    SELECT * FROM emp@sales; COMMIT; The following statement terminates the session in the remote database pointed to by the sales database link:

    ALTER SESSION CLOSE DATABASE LINK sales; To close a database link connection in your user session, you must have the ALTER SESSION system privilege.

    Note: Before closing a database link, first close all cursors that use the link and then end your current transaction if it uses the link.

    See Also: Oracle Database SQL Language Reference for more information about the ALTER SESSION statement

提交回复
热议问题