Replicate only certain databases - mongodb

I have one instance of database on local server, another on remote. So when internet is gone, application works on local database. After internet connection is reestablished I want to sync these two databases. I have two questions:
How to replicate only one database. (there are several databases on instance);
I have only succeeded to replicate instances on same machine (when one host is localhost and another is remote instance, it throws error), how to replicate database on different machines?

How to replicate only one database. (there are several databases on instance);
You can make the other database as Arbiter. It does not have a copy of data.
I have only succeeded to replicate instances on same machine (when one host is localhost and another is remote instance, it throws error), how to replicate database on different machines?
looks like a network setup problem to me. Test Connections Between all Members

Related

SQL Live Backup Over Intermittent Connection

I have a few PCs that have local PostgreSQL databases running, just logging data. Data is only ever inserted, never removed or updated. The remote PCs are connected to the internet by cellular modem and depending on their location, often do not have internet access. When they do have an internet connection I would like them to push a copy of their databases to a central location and keep the remote database up to date with any new data. Essentially, I need an 'rsync' for databases.
At first it seemed like what I need is to set up PostgreSQL Hot-Standby but I'm unsure if this is actually what I need because my situation seems to differ from the examples I've seen.
Each remote PC has a Postgres server with a single database that has a unique name, the tables within the DBs have generic names. I would like to synchronize these databases to a single remote Postgres server. I think this should be okay due to the unique DB names.
My connectivity is very intermittent, days to weeks without a connection. I've seen PgAdmin be very reliable despite a terrible (cellular) internet connection, if Postges Hot-Standby is the same I may be alright.
As far as I can see my options are either to set up PostgreSQL Hot-Standby, or roll my own solution. I don't want to roll my own solution. However it is simple enough if I can't find anything better; a Python daemon run by systemd to find the diff between the local and remote DB, then push the new rows from the local to the remote DB. But I'm sure someone has solved this problem, I just haven't found the solution yet.
You don't need hot standby (which is the PostgreSQL term for being able to query the replicated database), but streaming replication. You need a central standby server for each intermittently connected remote database server. If you use replication slots, you can be sure that replication will never fall behind.

Synchronize local changes to remote database

I got a requirement to setup 2-way data sync between main remote Postgresql DB and a local one. Main DB is used for multi-tenant access, and local db is used only by one tenant. So I need to sync only this tenant data. Local DB is installed on tenant's site and should be used only when internet connection is down. So, when there is internet connection, use remote DB and sync all the changes to local. When internet is down, switch to local DB. When internet is back online, sync local changes to remote.
I tried to figure out how to set this up, but it seems that Postgres replication isn't suitable for this case.
I need a tool that is capable of partial table sync both ways. Should I, maybe, consider changing DB design?

enabling multiple instances of mongodb on Ubuntu 20.04

I am working on a SaaS application where there will be a separate database for each tenant and one landlord/master database for the landlord. So
foo.example.com will connect the sales_foo database
bar.example.com will connect the sales_bar database and so on.
Now I have two environments, staging and testing both on the same server managed by a virtual host. So the problem is if I have 10 tenants then there will be 10 databases plus one landlord database. These all databases should be in one environment and one environment should not access other environment's databases. How can I achieve this?
Till now I have created separate .conf file for each environment and I can start mongod process with that conf as well. But how can I keep it enable all the time? Is it possible?
On a side note, I am using laravel for interacting with database.

Mirror one database to another in PostgreSQL

I know the way to set up a Master/Slave DB in Postgres is having 2 DB servers, but unfortunately i have only one server for now.
How can i mirror my production db into another "backup db" in "real_time"? I want to give access to another user to the mirrored db, so even if he does something there it will not affect production.
Nothing stops you setting up hot standby streaming replication, or another replication option like Londiste, between two PostgreSQL instances on the same computer.
The two copies of PostgreSQL must use different ports, but that's the only real restriction.
How to set up the second PostgreSQL instance depends on your operating system and how you installed PostgreSQL, which you have not mentioned.
You'll want to use streaming replication with hot standby if you want a read-only replica. If you want it to be read/write, then you can do a one-off copy of the database with pg_basebackup and not keep them in sync after that. Or you can use a tool like Londiste to replicate changes selectively.
You can run multiple instances of PostgreSQL on the same computer, by using different ports.

MAMP, One computer, two users, shared database

Two developers often share the same system, and both have local copies of the project and try to connect to a local database. Both users can see the database, but tables and their data are only visible to the database's original author.
We've tried giving all permissions to both users, but it seems the only thing that works is to duplicate the database.
Is there a way around this?
Thanks in advance!
You would probably be better off hosting a separate MySQL instance on it's own machine, and then configure your code to connect to that database instead of the MAMP-hosted one. That being said, you will need to open the port on the firewall of the MAMP(0) for the MAMP-MySQL (usually port 8889). Then, the script on the MAMP(1) needs to be configured to connect to MAMP(0) database on the newly opened port.
You will also need to GRANT privileges for user(1) on the MAMP-host(0) database.
A connect string from MAMP(1) would look like:
$db_url = 'mysqli://user:password#mamp0.local:8889/es_forms_drupal';
Hopefully that makes some sense.