I'm currently working on a Django application that interacts with an Oracle database. My application needs to execute SQL queries on a remote Oracle database, which is configured in the settings.py file.
The SQL queries I'm trying to execute have a syntax similar to:
SELECT * FROM table@source
Here, source is a different database than the one currently executing the query. Both the source and target databases are Oracle databases.
Despite the remote database being configured in settings.py, I encounter the following error when executing the first query:
ORA-02019: connection description for remote database not found
I'm looking for guidance on how to resolve this error. Here's some additional information that might be helpful:
I've confirmed that the remote database is accessible outside of the Django environment. The user credentials used in settings.py have the necessary privileges. The application works fine with local database queries. Has anyone encountered a similar issue or can provide insights into what might be going wrong? Any advice on configuring Django to work seamlessly with remote Oracle databases using database links would be greatly appreciated.
Thank you in advance for your help!
SELECT * FROM table@source
@source
means that your client (python/django on your local machine) talks to one database (presumably, in this case, the target
database) and then that target
database opens a database link to the source
database where the table
table is located and performs the query and then the result set is sent back to the target
database and then back to the client.
When you use a database link, you are NOT connecting directly to the source
database so anything specified in the settings.py
is irrelevant.
Either:
Do not use database links and use:
SELECT * FROM table
And tell Django to use the connection to the source
database that is specified in the settings.py
(See the Multiple Databases - Django Documentation for more details); or
Only specify the target
database in settings.py
and create a database link on target
to the source
. Something like:
CREATE PUBLIC DATABASE LINK source USING 'insert_connection_string';
(Read the documentation link above and adapt as appropriate.)
Then you can connect to target
and use:
SELECT * FROM table@source