Skip to content

Commit

Permalink
oradb-manage-statspack: New role for Statspack (#41)
Browse files Browse the repository at this point in the history
* oradb-manage-statspack: new role for Statspack

The new role could be used to install and configure Statspack jobs
in nonCDB, CDB and PDBs.
  • Loading branch information
Rendanic authored Sep 11, 2021
1 parent abd02e2 commit 3a51c09
Show file tree
Hide file tree
Showing 7 changed files with 421 additions and 0 deletions.
38 changes: 38 additions & 0 deletions roles/oradb-manage-statspack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Role Name
=========

A brief description of the role goes here.

Requirements
------------

Do not create the perfstat user before creating the statspack
inside the database. The detection of existing statspack installation
is based on the perfstat user. The installation will be skkipped when
user is existing.

Role Variables
--------------

The following example only shows mandatory variables from oracle_databases:

```yaml
oracle_databases:
- oracle_db_name: DB1
oracle_db_type: SI
statspack:
state: present
tablespace: sysaux
tablespace_temp: temp
purgedays: 14
snaplevel: 7
snapinterval: "FREQ=hourly;byminute=0;bysecond=0"
```
Dependencies
------------
Author Information
------------------
Thorsten Bruhns <[email protected]>
26 changes: 26 additions & 0 deletions roles/oradb-manage-statspack/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
# Global Defaults for Purge and Snapshot-Jobs.
# could be overwritten per dtabase with:
# oracle_databases:
# - oracle_db_name: test
# statspack:
# purgedays: 60
purgedays: 35
purgeinterval: "FREQ=daily;byhour=3;byminute=15;bysecond=0"
snapinterval: "FREQ=hourly;byminute=0;bysecond=0"
snaplevel: 7

db_user: system
db_password_cdb: "{% if dbpasswords is defined and dbpasswords[dbh.oracle_db_name] is defined and dbpasswords[dbh.oracle_db_name][db_user] is defined%}{{dbpasswords[dbh.oracle_db_name][db_user]}}{% else %}{{ default_dbpass}}{% endif%}" # noqa yaml
db_password_pdb: "{%- if dbpasswords is defined and dbpasswords[pdb.0.cdb] is defined and dbpasswords[pdb.0.cdb][db_user] is defined -%}
{{dbpasswords[pdb.0.cdb][db_user]}}
{%- else -%}
{{ default_dbpass}}
{%- endif -%}"

db_service_name: "{% if dbh is defined %}
{%- if dbh.oracle_db_unique_name is defined %}{{ dbh.oracle_db_unique_name }}
{%- elif dbh.oracle_db_instance_name is defined %}{{ dbh.oracle_db_instance_name }}
{%- else %}{{ dbh.oracle_db_name }}
{%- endif %}
{%- endif %}"
43 changes: 43 additions & 0 deletions roles/oradb-manage-statspack/files/spcreate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/bash
set -euo pipefail

cd $HOME

env | grep ^ORACLE | sort

PDB=${pdb_name:-"_"}

${ORACLE_HOME}/bin/sqlplus -S -L /nolog <<EOF
conn / as sysdba
define perfstat_password=${perfstat_password}
define temporary_tablespace=${temporary_tablespace}
define default_tablespace=${default_tablespace}
define purgedates=${purgedates}
define snaplevel=${snaplevel}
whenever sqlerror exit 1 rollback
begin
if '${PDB}' <> '_' then
execute immediate 'alter session set container = ${PDB}';
end if;
end;
/
@?/rdbms/admin/spcreate
set echo on
alter session set current_schema=perfstat;
PROMPT Fixup for idle Events (old stupid bug from Oracle...)
-- Re-fill STATS\$IDLE_EVENT with latest idle events that Oracle regularly forgets to update.
delete from perfstat.STATS\$IDLE_EVENT;
insert into perfstat.STATS\$IDLE_EVENT select name from V\$EVENT_NAME where wait_class='Idle';
commit;
PROMPT Create custom index for selecting sql_id from STATS\$SQLTEXT
create index perfstat.STATS\$SQLTEXT_UK1 on STATS\$SQLTEXT(sql_id, piece);
exit
EOF
23 changes: 23 additions & 0 deletions roles/oradb-manage-statspack/files/spdrop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/bash
set -euo pipefail

cd $HOME

env | grep ^ORACLE | sort

PDB=${pdb_name:-"_"}

${ORACLE_HOME}/bin/sqlplus -S -L /nolog <<EOF
conn / as sysdba
whenever oserror exit 1 rollback
begin
if '${PDB}' <> '_' then
execute immediate 'alter session set container = ${PDB}';
end if;
end;
/
@?/rdbms/admin/spdrop
exit
EOF
3 changes: 3 additions & 0 deletions roles/oradb-manage-statspack/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
dependencies:
- role: orasw-meta
Loading

0 comments on commit 3a51c09

Please sign in to comment.