User Tools

Site Tools


snippets

This is an old revision of the document!


Table of Contents

Snippets

Protecting an Apache Web Server directory with htaccess

Protecting a lighttpd directory with htaccess

Generate an MD5 hash with the tools above and paste into this file

2@@

Check modules.conf file to ensure mod_auth and mod_rewrite are enabled

3@@

Alter the lighttpd.conf file to allow the authentication

4@@

Restart the lighttpd server

5@@

I tried it with htdigest but could not get it to protest the directory!

6@@

Rename a datafile if the filename contains junk / unprintable characters

7@@
  • Oracle have a document that describes a few ways of doing it in Note 824473.1

If the filename contains control characters and cannot be selected in the normal way, use ls -ali to find the node number and then use find with -inum to rename (or move) the file

8@@

Work out what the database thinks the name is and rename it there too! AskTom has a discussion on it here

9@@

You can see there's a 127 just before the .dbf… this crept in a the backspace key was not working correctly.

10@@

Generate creation of directory names from dba_directories

Before deleting or dropping directories in the database, use this script to generate the create statements

11@@

Check if current (dot) directory is in PATH variable

Using bareword comparison to check PATH variable

12@@

tail a logfile from within the script you are writing it to

13@@

Dump package, procedure etc. from dba_source in a way that it can be used to recreate it

From Ask Tom

14@@

A trick to exit out of SQL*Plus (using divide by zero) depending on answer to a question

This example is taken from ReviewLite.

15@@

How to uninstall optional components such as OWB, APEX, EM, OLAP, OWM from an Oracle database

Find unique indexes / primary index / key columns in a table

16@@

Display the oracle instances running on the local server

sed could be shorter but this one works cross-platform

17@@

Display which databases are scheduled for backup in cron

18@@

Trace SQL statements using autotrace and explain plan

If the plustrace (plustrc.sql) role has been granted, explaining sql statements (without running the statement) is as easy as

19@@

Write to a trace log from PL/SQL

20@@

Invisible / hidden / virtual columns

Write to the alert log from PL/SQL

Writes to trace file

21@@

Writes to the alertlog

22@@

Writes to the alertlog and trace file

23@@

Also available, KSDIND, KSDDDT and KSDFLS

Do distributed SQL transactions exist?

24@@

if yes, and to commit them…

25@@

Setup optional parameters and default values in an SQL*Plus script

Some forgotten SQL*Plus tricks from the good old days and some new ones…

26@@

Display / show users with sysdba & sysoper privileges

27@@

Show path names of data files using instr

Use to find the pathnames of all the filesystems/directories in which a database is housed.

28@@

Does a dataguard standby exist for this database?

29@@

gives something like this if found…

30@@

List values for all init parameters in v$parameter (including default values for undocumented (hidden) parameters

31@@

Log file reports pipe errors

Found these in the log file

32@@

This could be due to a timeout on the pipe.<br /> Increase parameters and restart agent. Add following lines to or.config:

33@@

Find the most recent archived SCN number

34@@

Monitoring says database inactive

  • Check the candle user password has not expired in the database.
  • There may be a clue in the log file. Check /opt/IBM/ITM/logs/`hostname`_or_${SID}_col.out
  • Check limits for itmora account in /etc/security/limits. Should be same as oracle user.
  • Check the config file. We had this issue when a new ORACLE_HOME was installed but the cfg file still had the old one in it.
35@@
36@@

Solution:<br />

  • Change all occurrences of 11.2.0.1 to 11.2.0.3
  • Restart agent

Alerts due to password expiring (or being changed in the database but not in ITM!)

37@@
38@@

Solution:<br />

  • Run agent reconfigure to setup the new password for the candle user (tivoli)
39@@
  • Restart agent
40@@

Many agents started with root user instead of itmora

This can happen if the server is rebooted before the agents have been added to the itmora list using kdyedit / kciedit

41@@
42@@

Solution: Add these instances to the itmora list

43@@
44@@

Kill any agents still running as root

45@@

Because these agents were owned by root, there will be permissions issues when trying to restart the agents with itmora so these need to be fixed before restarting the agents.<br /> The simplest way of doing this is to run lockdown.

46@@

See which processes are causing paging

47@@

How to return several variables from SQL*Plus back to Korn shell script

Return multiple columns/elements from Oracle to shell script at the same time

48@@

How to get a shell environment variable from the operating system into the SQL or PL/SQL environment

This has been bugging me for years. Something you would think simple… what is ORACLE_HOME? I know it's a question mark at the SQL prompt but how to get it's O/S value?

49@@

or in SQL*Plus

50@@

That got me thinking… if this just gets stuff from the environment, it can fetch any exported variable?!?!<br /> From the shell:

51@@

and now in SQL*Plus:

52@@

Wow!

How long/wide can a database name/sid be?

Depends on where you look but taking the minimum here as “safe”, it should still be limited to 8 characters…

53@@

This is 11gR2

54@@

What character set (characterset) was the database built with?

55@@

or

56@@

How to get value of ORACLE_HOME from shell environment into SQL*Plus or PL/SQL

57@@

How to find ORACLE_HOME from pmon process for a SID if there is no entry in oratab

If database is created without dbca (datafile and controlfile copy), no entry will be automatically made in /etc/oratab.<br /> So the problem is that you need to find out which of the ORACLE_HOMEs is being used by the running instances.

  • Solaris, Linux
58@@
  • AIX
59@@

or<br /> This command (ps eww) gives lots of information about the given process (pmon in this case). Tells you where the instance was started, whether it was started from SQL*Plus or RMAN, the http_proxy and loads more useful bits!

60@@

Escape the underscore(_) or percent(%) character in an SQL statement

The underscore matches any single character so to return data containing an underscore means having to use an escape character.<br /> Here I use the backslash(\) so it is easy for Unix people to understand the mechanism.

61@@

Validate, analyse and rebuild indexes

62@@

Rebuild unusable indexes on a table

63@@

Pull the latest cfengine changes now instead of waiting for scheduled time

For one host

64@@

On all hosts at the same time

65@@

Check status of datafiles without dba_data_files or v$datafile

If the database is in mount mode, most tables are unavailable. This query uses the x$ (c based) tables and are always available

66@@

Check highest allocated extent in datafile (likely slow when having many extents)

  • Script to Detect Tablespace Fragmentation ( Doc ID 1020182.6 )
  • How to shrink or reduce the datafile size by finding the high water mark (HWM) ( Doc ID 1600774.1 )
  • How to find Objects Fragmented below High Water Mark ( Doc ID 337651.1 )
67@@

Runup to this was…

68@@
69@@
70@@

Procedure to shrink space in tables and indexes

Written by Tom Kyte<br /> Depending on the Oracle version, this procedure may or may not work! It does not include the compact clause (neither does it re-analyse to prove it worked).<br /> Here is a worked example that shows the complete process - oracle-wiki.net

71@@

How to delete/kill a distributed transaction

From pouwiel.com

72@@

Be aware that the support document 159377.1 does not speak of the rollback force. If you don’t execute that particular command it will not work. <br />

ORACLE_BASE is getting set to the same value as ORACLE_HOME when using . oraenv

Permissions problem. Make sure the user has write access to oraclehomeproperties.xml file!

73@@

Change permissions as appropriate. A different approach which should give the same end result would be to grant the orabase executable the setuid bit.

74@@

This allows any user to set the environment as the orabase executable will be run with the permissions of its owner.

Move table partitions to a different tablespace

Are you getting errors due to partitions belonging to a different tablespace and you want to drop the current tablepace?<br /> ORA-14404: partitioned table contains partitions in a different tablespace<br />

Find tables with partitions in more than one tablespace

75@@

See which tables have partitions across multiple tablespaces…

76@@

Generate statements to move the partitions from one tablespace to another…

77@@

What's left hanging around?

78@@

What edition is my database (Standard, Enterprise, XE...)?

Only works from 12c :-(

79@@

Is database a CDB with PDBs?

Needs a bit of work. Won't work pre-12c obviously and also not on Standby databases if they are in MOUNT mode

80@@

version 2

81@@

List triggers in the database

This query specifically lists after login triggers

82@@

List the pluggable databases (PDB) in a container database (CDB)

The network_name column shows what you should find in tnsnames.ora for this db connection

83@@

or

84@@

Start and stop a pluggable database

85@@
86@@

Swith to a pluggable database

87@@

Reopen pluggable databases at container startup

By default pluggable databases in a container remain in a MOUNT state when the container starts up.

88@@

To modify this, open it and save its state

89@@

To see a log of issues with pluggable databases

90@@

What is the current container id in a cdb?

CDB$ROOT is container id 1. User containers start from 2.

91@@

What is the current container name in a cdb?

92@@

or just

93@@

Switching Between Containers

94@@

Direct connection to pluggable database

These must be made using a service (defined in tnsnames.ora). Each pluggable database automatically registers a service with the listener (v$services).

95@@

or using ezconnect

96@@

What platform is the database running on?

Could be useful for handling line endings…

97@@
98@@

Is the database 32 or 64 bit?

If the answer is 1,7,10,15,16 or 17, then it is 32bit, everything else should be 64bit.

99@@

What features is my database using?

Before converting to Standard Edition, check the features here - some may be Enterprise specific.

100@@

How many redo log switches per hour?

101@@

or a bit fancier version…

102@@

Show redo log groups/members

103@@

Korn shell timestamp function

Example usage: echo “`ts`: Checking backup status”

104@@

Drop a database

Dropping a database including backups should be considered criminal in a production environment!

105@@

or

106@@

Use sub-select or in-line views to update base tables

Inline views can be used to update base table data

107@@

Use sub-select or in-line views to delete base table data

A different way to delete rows in base tables, using Inline views or subselect

108@@

Mass update of files using perl inline script

109@@

How to use vi-style editing in SQL*Plus

These instructions are for Redhat but other versions will be very similar

110@@
111@@

or for general command use…

112@@

Execute an SQL statement on all databases on all servers for a customer

Run from customer's management server

113@@

or

114@@

Where is the alert log/alertlog?

Older systems

115@@

Newer systems

116@@

Grant normal users access to the alertlog table (sys.x$dbgalertext)

117@@

Search alert log for ORA-00600 and ORA-07445 errors

Scan the database table version of the alertlog for errors without reporting what was already found.

118@@

Simulating errors in alert log

Sometimes you need to inject error messages into the alertlog to test your monitoring system. This generates the entries in the alertlog and in x$dbgalertext table.

119@@

This additionally creates a trace file.

120@@

tail the database alert log

If an ADR error is displayed, then ORACLE_SID is probably not set

121@@

What is my WAN ip address?

122@@

or

123@@

Wait for child pid to finish in background and report its status

124@@

or

125@@

Real world example

126@@

It uses a clever package, dbms_sys_sql.<br /> Also useful for executing anything on behalf of another user.<br /> Here is an example on how to create private database link for a user.

127@@

Here we can generate SQL to rebuild the links for future use. Note the password is no longer stored in this column.

128@@
129@@

Create a comma separated list of columns from a select statement

Method 1:

130@@

or

131@@

Method 2 (undocumented and cannot therefore be relied on to continue working in the same manner):

132@@

Start an instant one-line webserver in current directory

Need to quickly share/copy a file or read an html file on Linux? Start a web server!

133@@

and point your browser to http://localhost:8000<br /> or

134@@

Get SQL*Plus to generate HTML

One way to do it… use -m(arkup) option to specify:<br /> html on/off - specifies whether to output html output or not head - specify your own customised head contents<br /> spool off - as a part of the -m tag means do not print the default &lt;html&gt;, &lt;head&gt; and &lt;body&gt; tags<br />

135@@

or

136@@

besides html and head, you can also specify:<br /> body - specify your own customised body attributes<br /> table - override the default table options<br /> entmap - turn on or off the html replacement characters (&lt, &gt, etc…)<br /> preformat - uses the &lt;pre&gt; tag to format output exactly as required<br />

  • another little gem…
137@@

HTML SELECT - Trigger JavaScript ONCHANGE event even when the option is not changed

138@@

Display horizontal bar graph in HTML table data cell

Using Perl

139@@

Depending on which way around the divs are, you get different interpretations

140@@

References

snippets.1544130327.txt.gz · Last modified: 2018/12/06 21:05 by 91.177.234.129

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki