I have 2 DB2 instances in one machine, instances DB2 and DB2_01.
DB2 was the first instance I've installed, DB2_01 was the last installed and is the default instance. When I use db2.exe in the instance DB2_01 with CREATE DATABASE XXX, the db2.exe try to create XXX in the instance DB2 and not in DB2_01.
What can I do to direct my comands to the right instance (DB2_01) using db2.exe ?
Can I have one database called XXX in instance DB2 and other database with the same name XXX in the other instance?
You can explicitly attach to the instance first before issuing your command.
i.e.
db2 attach to DB2_01
db2 create db XXX
And yes you can have the same database name in different instances. Each instance is a separate database management environment.
Hope this helps.
Related
I am trying to use pg_cron to schedule calls on stored procedure on several DBs in a Postgres Cloud SQL instance.
Unfortunately it looks like pg_cron can only be only created on postgres DB
When I try to use pg_cron on a DB different than postgres I get this message :
CREATE EXTENSION pg_cron;
ERROR: can only create extension in database postgres
Detail: Jobs must be scheduled from the database configured in
cron.database_name, since the pg_cron background worker reads job
descriptions from this database. Hint: Add cron.database_name =
'mydb' in postgresql.conf to use the current database.
Where: PL/pgSQL function inline_code_block line 4 at RAISE
Query = CREATE EXTENSION pg_cron;
... I don't think I have access to postgresql.conf in Cloud SQL ... is there another way ?
Maybe I could use postgres_fdw to achieve my goal ?
Thank you,
There's no need to edit any files. All you have to do is set the cloudsql.enable_pg_cron flag (see guide) and then create the extension in the postgres database.
You need to log onto the postgres database rather than the one you're using for your app. For me that's just replacing the name of my app database with 'postgres' e.g.
psql -U<username> -h<host ip> -p<port> postgres
Then simply run the create extension command and the cron.job table appears. Here's one I did a few minutes ago in our cloudsql database. I'm using the cloudsql proxy to access the remote db:
127.0.0.1:2345 admin#postgres=> create extension pg_cron;
CREATE EXTENSION
Time: 268.376 ms
127.0.0.1:2345 admin#postgres=> select * from cron.job;
jobid | schedule | command | nodename | nodeport | database | username | active | jobname
-------+----------+---------+----------+----------+----------+----------+--------+---------
(0 rows)
Time: 157.447 ms
Be careful to specify the correct target database when setting the schedule otherwise it will think that you want the job to run in the postgres database
.. I don't think I have access to postgresql.conf in Cloud SQL ...
Actually there is, you can use the patch command.
according to pg_cron doc, you need two change two things in the conf file:
shared_preload_libraries = 'pg_cron'
cron.database_name = 'another_table' #optionnaly to change the database where pg_cron background worker expects its metadata tables to be created
Now, according to gcloud
You need to set up two flags on your instance:
gcloud sql instances patch [my_instance] --database-flags=cloudsql.enable_pg_cron=on,cron.database_name=[my_name]
CAREFUL, don't use twice the command "patch" as you would erase your first setting. Put all your changes in one command
You also might want set cron.database_name in postgresql.conf (or flag in CloudSQL)
cron.database_name = mydatabase
I have created a new Arora Serverless PostgreSQL cluster and I am trying to use the Query Editor.
What do I enter in the Database Name text field? Where do I find the name of the database? Is it the same are the cluster name?
Note: I have enables the Data API when I created the DB
Creation of database is an optional setting when you create your Aurora serverless:
If you haven't done that you have to create your db using traditional way.
This is the name of the database within the cluster, not any hostname or individual node. The target hosts are specified in Database instance or cluster label.
When you created your database cluster you could optionally specify a database that would be created on the host. This default database is viewable from within the console interface. Otherwise if you created the target database after the cluster launched, specify that database name instead.
Whenever I create a Db2 service in IBM Cloud, it takes the default database name BLUBDB. I want to change to user specific name like TESTDB?
Most of service plans for Db2 Warehouse on Cloud (formerly dashDB), then there is only a single database and the name is preset to BLUDB for simplicity. If you want to have more control, you could go with Db2 Hosted on IBM Cloud.
Alternatively, if you are already locally cataloguing the database you could add an alias.
For example:
db2 catalog tcpip node mynode remote dashdb-myinstance.bluemix.net server 50000
db2 catalog database bludb as testdb at node mynode
I am trying to use my local DB2 Express-C edition to access remotely a db2 database running on a remote machine at IP 192.168.48.189. The remote machine is running a DB2 Workgroup Server edition.
They are both version v10.1 and I am running them on LINUX.
First of all Is that possible?
When I try the following call it always returns me this error.
If I understood correctly
db2tcp1 is a new node I need to create on my local to be able to connect
db2inst1 is the db2 instance name of the remote db2 instance.
My local instance as well is named db2inst1 like the remote one.
Is my command below correct?
db2 "CATALOG TCPIP NODE db2tcp1 REMOTE 192.168.48.189 SERVER db2inst1"
SQL0512N A three-part name "" that references a remote object is not
supported in the context in which it appears. Reason Code = "".
You can catalog remote databases in your local installation, it does not matter the db2 edition. Your command has a problem with the "server", you put the port number there. I know, that is weird.
Once you have catalooged the instance you will catalog the databases. Make sure to open the ports between two servers.
I have two instances on two separate AIX servers. Both DB2 databases are up with their sample databases. I want to connect with one DB2 instance from the other instance.
I am new on DB2 and want to know how can I do that.
I have executed following commands:
This path is client instance:
#. /home/db2inst2/sqllib/db2profile
db2 catalog tcpip node db2serverinst remote lpar1 server 50005 remote_instance ctginst1
db2 => terminate
DB20000I The TERMINATE command completed successfully.
# db2 connect to db2serverinst user ctginst1
Enter current password for ctginst1: SQL1031N The database directory cannot be found on the indicated file system.
SQLSTATE=58031
The term "Connect to an instance" is not correct. The correct one is to attach:
Machine A
db2inst1
db-1
db-2
sample
Machine B
db2inst2
db-3
db-4
sample
db2inst3
sample
If you want to execute commands from Machine A into Machine B, you have to catalog db2inst2 AND/OR db2inst3 in db2inst1 (catalog tcpip node). Remember that you have to give different names to each cataloged object.
Once you have cataloged a remote instance, you could also issue database commands, but you have to catalog remote databases. You can have a remote sample, and a local sample, but alias should be different.
If you cataloged db2inst2 instance as db2inst2 node in local node from Machine A.
And you cataloged sample database as sample-2 alias in local node from Machine A.
You could execute in Machine A.
db2 attach to db2inst2
db2 connect to sample-2
Attach is for 'administrative' things, like list applciations, create db, etc.
Connect is to use the database.
You have only cataloged DB2 instance. You need to catalog the database at the remote server:
db2 catalog database XXXX at node db2serverinst
Obviously, you'll need to replace the XXXX with the actual name of the remote database. Once you've cataloged the database, you can then connect:
db2 connect to XXXX user ctginst1
Note, this only defines the connection. You won't be able to access objects within this remote database from other databases within the local instance without configuring federation.