Elixir/Phoenix - Connect to external database - phoenix-framework

I connected the main database in the dev.exs and it works fine. But in my project I plan to use several databases. I know that in the file dev.exs can connect multiple databases but this option doesn’t suit me. Databases connections will be stored in the main project database. I want to know: how can I connect to different databases using the elixir code without using a file dev.exs?

You can start multiple instances of your Repo with different connection options.
Then, use the Repo.put_dynamic_repo/1 function to tell the Repo which of the databases should be used for queries in the current process. (The documentation for this function also tells you how to start more of the same repo).
There's also a discussion document that goes more in-depth about this topic: https://hexdocs.pm/ecto/replicas-and-dynamic-repositories.html

Related

Database Link - Test connection does not work

I have two databases that have tables with identical schema. I want to compare the two tables. I learned that cross DB queries need a Database Link.
I use SQL developer and here are the properties of the connection that works
Connection Name: MyConn
UserName:SomeUser
password:SomePassword
Connection Type: Basic
Role: default
Host Name: 12.12.12.12
port:2521
SID: xe
I tired this command to create Database link
CREATE DATABASE LINK MyDBLink
CONNECT TO SomeUser
IDENTIFIED BY "SomePassword"
USING '(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=12.12.12.12)(PORT=2521))
(CONNECT_DATA=(SID=xe)))';
The command creates a link but when I try to test the link, the connection does not work. The connection times out in 60s.
Am I missing something ?
The Database-Link is between the two databases and not "outgoing" from your local sqldeveloper/client.
So even if you can reach the remote database from your local client, the remote database-server where you created the link might (and in this case indeed does) not reach the target of the database link.
The database link itself is created no matter if the remote database is reachable, or the credentials are incorrect, etc.
If you have the possibility you should directly log on the database server of the database where you created the link and check the network connection to the database server you want to reach from there. Using telnet might help you.
The best solution is to look at the network or operating system and open a path between the two servers, and then the database link should work. If that's not possible, you can use your desktop PC as a proxy.
The official way to route around network issues is to use Oracle Connection Manager. But in my experience that program is a bit hard to configure.
Another option is to create a database on your desktop, and create two database links to each server. If this desktop database is only used for linking to others, then the free Express Edition should be good enough. If you go down this route, be careful of performance problems when involving 3 databases. You'll probably want to compare hashes instead of actual data, to avoid network problems.

Oracle application - migration to Exadata server

We have an upcoming migration of our Oracle database to an Exadata server. I want to clarify some issues I have thought of:
Will there be any issues with the code - performance issues? Exadata has another type of optimizer, it doesn’t uses indexes, has a columnar optimizer, if I’m not misleading,
Currently there are some import or export files generated on the database server (accessed via Filezilla). I understand that at Exadata the database server is inaccessible, and I suspect that either:
• we will have to move those files to another server - Oracle knows only FTP (which has ports closed at our client) -> how do we write / read from another server? (as far as I understand, they would like to put all the files on the WAS server)
• or we will need to import the files into the table using the java application and process them from there (and the same with the exported files).
Files that come automatically from other applications can be written to the database server? Or we have the same problems as for the manual part.
We have plenty of database jobs that run KSH scripts on the database server - is there a problem with them? I understand they should also be moved to the WAS server, but I do not know how Oracle will call them from there.
Will there be any problems with Jenkins deployments? Anything changed? Here we save the SQL/PLSQL sources in some XML files, from which the whole application is restored (packages, configuration tables, nomenclatures ...) (with the exception of the working data) (the XML files are read through a procedure from an oracle directory).
If you can think of any other issues concerning this migration, any problems you have encountered during or after the migration to Exadata, please share!
Thank you,
Step by step:
On exadata you are going to have the same optimizer behaviour with some improvements because the exadata may improve full table scan performance thanks to smart full scans. Indeed the exadata is able to avoid retrieving data blocks in fts because it knows in advance they do not contain neeeded data.
In the exadata you can export to external servers DBFS file systems, that might be useful for external tables, imports/exports and so on.
You can write your files on the DBFS you can configure.
You could use your DBFS, if you want the ksh files are accessed from outside your exadata.
Let your oracle directory point to a directory in the DBFS file system where you put your xml files and you are done.

Can I connect the jdbc connected static Derby data file in remote repository?

I have to load two Derby instances that reference same data Derby file in a remote repository.
Is it possible? How can I achieve this? Would you give detailed information?
Two different connections in the same Derby app is ok because Derby uses Java synchronization features to coordinate their access to the db.
Two different apps cannot use Java synchronization because that only works inside a single Jvm class loader so instead Derby locks the db and only allows one app at a time to access the db.
That is the benefit of the Derby network server because many apps can access the db simultaneously via the network server.
There is a hybrid mode by which one embedded app can also serve as the network server for other apps but it is complex and usually not the best choice.
Update: You can find more information about embedded servers in these docs: http://db.apache.org/derby/docs/10.11/adminguide/cadminov825149.html and http://db.apache.org/derby/docs/10.11/adminguide/radminembeddedserverex.html
or by searching the Internet for "Derby embedded server".

H2 Database multiple connections

I have the following issue:
Two instances of an application on two different systems should share a small database.
The main problem is that both systems can only exchange data through a network-folder.
I don't have the possibilty to setup a database-server somewhere.
Is it possible to place a H2 database on the network-folder and let both instances connect to the database (also concurrently)?
I could connect with both instances to the db using the embedded mode if I disable the file-locking, right?
The instances can perfom either READ or INSERT operations on the db. Do I risk data corruptions using multiple concurrent embedded connections?
As the documentation says; ( http://h2database.com/html/features.html#auto_mixed_mode
)
Multiple processes can access the same database without having to start the server manually. To do that, append ;AUTO_SERVER=TRUE to the database URL. You can use the same database URL independent of whether the database is already open or not. This feature doesn't work with in-memory databases.
// Application 1:
DriverManager.getConnection("jdbc:h2:/data/test;AUTO_SERVER=TRUE");
// Application 2:
DriverManager.getConnection("jdbc:h2:/data/test;AUTO_SERVER=TRUE");
From H2 documentation:
It is also possible to open the database without file locking; in this
case it is up to the application to protect the database files.
Failing to do so will result in a corrupted database.
I think that if your application use always the same configuration (shared file database on network folder), you need to create an application layer that manages concurrency

Using a VS2010 Database Project for only specific schemas in another database

thanks for reading...
Here's my problem:
The Background: I have been tasked with being a Build Manager (first time doing so). Among other things, this includes creating scripts to update the staging DB. I would like to utilize a Database Project for this so I may keep it in source control and also have it apart of TFS Labels to create a snapshot of the DB at the time of the build. This seems pretty straight forward to me.
The Setup: In our dev environment, we have a copy of our production DB. This DB is the one where our new data base objects will be deployed when we go live. We also have a copy of it in staging for testing.
The Goal: The only schemas (and related objects) I need in the Database Projects are limited only to the ones that aren't in production.
The Problem: When I create a new Database Project, I have no option to select only certain schemas to import (that I am aware of). Is there a way to only import Schemas A, B, and D and leave out dbo and C? Along with this, is it possible when using the 'Schema Comparison' to compare only selected schemas within the database?
Please let me know if my question and information are incomplete.
Thanks.
-Justin

Resources