The Oracle listener

In order to access to the same database where are you working outside the database server you must activate the service called listener, it has to be listening.

It can happens that the database is properly raised and can not connect from other servers, which are also set correctly (correct TNSNAMES, etc.).. 

In these cases could be that the listener has a problem, or simply has not been initiated.

To Check the status, start or stop it is very simple. Just open a command line session (console terminal, etc..) with the user that has installed the database, and run the lsnrctl command with the following parameters:

  • Check your state:
      > lsnrctl status

  • Stop the listener:
      > lsnrctl stop

  • Start the listener:
      > lsnrctl start

Keep in mind that when you stop the listener, the connections that are already in the database won't be closed, so a short stop is not very traumatic, only connections trying to enter while the listener is stopped are rejected, should not affect anyone who already has an opened session.

Remote access using Oracle DBLINK

The easiest way to access from an Oracle database objects from another Oracle database is using a DBLINK (being the easiest does not mean that it is always the most desirable, the abuse of DBLINKS can create many problems, both of performance and safety)

To do this it's necessary a user with CREATE DATABASE LINK privilege, and create a DBLINK in the source database (A) by a simple statement such as:

Create database link LNK_from_A_to_B connect to USER identified by PASSWORD USING 'B'; 

'LNK_from_A_to_B' is the name of the link, 'USER' and 'PASSWORD' are the IDs of the user who will use the link to connect, which will inherit the permissions of all access through the link, and B is the name of the database's instance.

Using the DBLINK we can connect to the objects with the remote database's permissions that user has been provided in the creation statement.

To reference an object from the remote database should indicate the name of the object, concatenated with the character '@' and the name that we had given to the DBLINK.

Example: 

select * from TABLA@LNK_from_A_to_B