Slick 3.0.1 limit connections to db - postgresql

I'm looking at doing something as simple as limiting the number of connections that Slick 3.0.1 has to a postgres db.
This doesn't work since after a while the number of connections goes to 18 for example.
source-db = {
dataSourceClass = "org.postgresql.ds.PGSimpleDataSource"
properties = {
url = "jdbc:postgresql://..."
user = "..."
password = "..."
}
numThreads = 1
maxConnections = 5
}

If you are in a play application you are probably using HikariCP. To change the settings you need to add something like this to the configuration:
hikaricp {
minimumIdle = 2
maximumPoolSize = 5
}

Related

Connection of PostgreSQL database with corda

How to connect PostgreSQL database using pg admin to corda instead of H2 database ?
What are the changes to be done in node.conf file before the nodes are up ?
As mentioned in the comments, all you need is adding the followings node.conf file after you have generated your node.
dataSourceProperties = {
dataSourceClassName = "org.postgresql.ds.PGSimpleDataSource"
dataSource.url = "jdbc:postgresql://[HOST]:[PORT]/postgres"
dataSource.user = [USER]
dataSource.password = [PASSWORD]
}
database = {
transactionIsolationLevel = READ_COMMITTED
}
And please remember to wrap all the string values with double quotes (eg. "Username", "Password")

How to change max/min jdbc connections of akka-persistence-jdbc?

I am trying to change the minimum and maximum pool size of JDBC connections used by akka-persistence-jdbc.
I tried to change the following in my application.conf:
jdbc-journal {
slick.db.maxConnections = 2
slick.db.minConnections = 2
}
jdbc-snapshot-store {
slick.db.maxConnections = 2
slick.db.minConnections = 2
}
jdbc-read-journal {
slick.db.maxConnections = 2
slick.db.minConnections = 2
}
But it didn't change anything.
Eventually the solution is to change Lagom related configuration:
db.default {
async-executor {
numThreads = 2
minConnections = 2
maxConnections = 2
}
}

How to use Scaldi Conditions to do default binding

I am using Scaldi with Play and Slick in my application.
I need to bind a DatabaseConfig dependency to different configurations depending on some condition.
Mode = Dev => Oracle DB
Mode = UAT => Another Oracle DB
...
Mode = Test => Local H2 DB
No Mode specified => same as Mode = Test
How do I handle the last part? I tried to do the following but it does not work.
val inDevMode = SysPropCondition(name = "mode", value = Some("dev"))
val inTestMode = SysPropCondition(name = "mode", value = Some("test")) or SysPropCondition(name = "mode", value = None)
bind [DatabaseConfig[JdbcProfile]] when (inDevMode) to new DbConfigHelper().getDecryptedConfig("gem2g") destroyWith (_.db.close)
bind [DatabaseConfig[JdbcProfile]] when (inTestMode) to DatabaseConfig.forConfig[JdbcProfile]("h2") destroyWith (_.db.close)
val inTestMode = SysPropCondition(name=MODE, value=Some("test")) or SysPropCondition(name=MODE, value=None) or
Condition(System.getProperty(MODE) == null)

Is there a working example of Akka.net Persistence with MongoDb out there anywhere?

I am attempting to configure Akka.Net with journal persistence to MongoDb but it is throwing an exception that I can't quite figure out. Is there a reference example out there anywhere I can look at to see how this is supposed to work? I would have expected the examples in the unit tests to fill this need for me but the tests are missing for the MongoDb implementation of persistence. :(
Here's the error I am getting:
Akka.Actor.ActorInitializationException : Exception during creation --->
System.TypeLoadException : Method 'ReplayMessagesAsync' in type
'Akka.Persistence.MongoDb.Journal.MongoDbJournal' from assembly
'Akka.Persistence.MongoDb, Version=1.0.5.2, Culture=neutral, PublicKeyToken=null'
does not have an implementation.
and here is my HOCON for this app:
---Edit - Thanks for the tip Horusiath; based on that I updated to this HOCON and the Sqlite provider works but the MongoDb one is still giving an error.
<![CDATA[
akka {
actor {
provider = "Akka.Remote.RemoteActorRefProvider, Akka.Remote"
}
remote {
helios.tcp {
port = 9870 #bound to a specific port
hostname = localhost
}
}
persistence {
publish-plugin-commands = on
journal {
#plugin = "akka.persistence.journal.sqlite"
plugin = "akka.persistence.journal.mongodb"
mongodb {
class = "Akka.Persistence.MongoDb.Journal.MongoDbJournal, Akka.Persistence.MongoDb"
connection-string = "mongodb://localhost/Akka"
collection = "EventJournal"
}
sqlite {
class = "Akka.Persistence.Sqlite.Journal.SqliteJournal, Akka.Persistence.Sqlite"
plugin-dispatcher = "akka.actor.default-dispatcher"
connection-string = "FullUri=file:Sqlite-journal.db?cache=shared;"
connection-timeout = 30s
schema-name = dbo
table-name = event_journal
auto-initialize = on
timestamp-provider = "Akka.Persistence.Sql.Common.Journal.DefaultTimestampProvider, Akka.Persistence.Sql.Common"
}
}
snapshot-store {
#plugin = "akka.persistence.snapshot-store.sqlite"
plugin = "akka.persistence.snapshot-store.mongodb"
mongodb {
class = "Akka.Persistence.MongoDb.Snapshot.MongoDbSnapshotStore, Akka.Persistence.MongoDb"
connection-string = "mongodb://localhost/Akka"
collection = "SnapshotStore"
}
sqlite {
class = "Akka.Persistence.Sqlite.Snapshot.SqliteSnapshotStore, Akka.Persistence.Sqlite"
plugin-dispatcher = "akka.actor.default-dispatcher"
connection-string = "FullUri=file:Sqlite-journal.db?cache=shared;"
connection-timeout = 30s
schema-name = dbo
table-name = snapshot_store
auto-initialize = on
}
}
}
}
]]>
</hocon>
So, back to my original question: Is there are working MongoDb sample that I can examine to learn how this is intended to work?
Configuration requires providing fully qualified type names with assemblies. Try to specify class as "Akka.Persistence.MongoDb.Journal.MongoDbJournal, Akka.Persistence.MongoDb" (you probably don't need double quotes either, as it's not inline string).
An old thread, but here's a large sample I put together years ago using Akka.Persistence.MongoDb + Clustering: https://github.com/Aaronontheweb/InMemoryCQRSReplication

How to set up Slave Database configuration in vBulletin?

How to set up Slave Database configuration in vBulletin ? I set up like this:
$config['Database']['dbtype'] = 'mysql';
$config['Database']['dbname'] = 'xyz';
$config['Database']['tableprefix'] = 'vbulletin1_';
$config['Database']['technicalemail'] = 'xyz#abc.com';
$config['Database']['force_sql_mode'] = false;
$config['MasterServer']['servername'] = 'xyz';
$config['MasterServer']['port'] = 3306;
$config['MasterServer']['username'] = 'x';
$config['MasterServer']['password'] = 'xxxx';
$config['MasterServer']['usepconnect'] = 0;
$config['SlaveServer']['servername'] = 'abc';
$config['SlaveServer']['port'] = 3306;
$config['SlaveServer']['username'] = 'a';
$config['SlaveServer']['password'] = 'xxxx';
$config['SlaveServer']['usepconnect'] = 0;
This is depends from your slave DB credentials only. And "Slave DB" means that you have replicated DB on your host (vBulletin can't make this, it should be done automatically by your web server). So, if you have not a replicated DB, you should not setup Slave DB.
A Master-Slave setup is for performance. You send write queries to the master server, and most read queries to the slave server. It helps improve performance because write queries lock tables/rows depending on the database table type, and reads do not.
vBulletin forum