Search This Blog

Thursday, June 4, 2015

RMAN: Restore missing archivelogs


SQL> select sequence#, applied, to_char(first_time,’dd-mm-yyyy hh24:mi:ss’) first_time
from v$archived_log
order by sequence#;


SQL> select process,sequence#,status from v$managed_standby;
PROCESS STATUS SEQUENCE# FIRST_TIME
------------ ---------- -------------------
ARCH CONNECTED 0
ARCH CONNECTED 0
MRP0 WAIT_FOR_GAP 7279
RFS WRITING 7299


WAIT_FOR_GAP means thare are missing archivelogs. You need to recover them.


We first identify whose are missing:

[oracle@ora-test ~]$ sqlplus / as sysdba
SQL> select * from v$archive_gap;


   THREAD# LOW_SEQUENCE# HIGH_SEQUENCE#

---------- ------------- --------------

         1          7279           7286




We then use RMAN to recover them:

[oracle@ora-stb ~]$ rman target / catalog rman/password@rman_repo
RMAN> restore archivelog sequence between 7279 and 7286;



You can now check
[oracle@ora-stb ~]$ ls –l /archivelog_folder/arch_72[7-8]*

Tuesday, May 26, 2015

Postgres SQL: Day to day tips

Dates

transform an int as readable timestamp:

select to_timestamp(FIELD_TO_CONVERT) from table;

Thursday, April 9, 2015

Postgres SQL: Install and first launch

Create and setup the postgres user:
[root@localhost ~]# useradd postgres -m /home/postgres

If you don't have the home dir yet, you can add it at a later stage. You just need to stop all processes used by it first.
[root@localhost ~]# mkdir -p /home/postgres
[root@localhost ~]# chown postgres:postgres /home/postgres
[root@localhost ~]# usermod -d /home/postgres postgres

Then, connect as postgres and start the server:
-bash-4.3$ initdb -D /var/lib/pgsql/data/
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
creating configuration files ... ok
creating template1 database in /var/lib/pgsql/data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    postgres -D /var/lib/pgsql/data/
or
    pg_ctl -D /var/lib/pgsql/data/ -l logfile start

Start the server:
-bash-4.3$ pg_ctl -D /var/lib/pgsql/data/ -l logfile start

You can now create a database and connect to it:
-bash-4.3$ createdb test1
-bash-4.3$ psql test1
psql (9.3.6)
Type "help" for help.

test1=#


To stop the server:
$ pg_ctl stop