Friday, 10 January 2014

Temporary Tablespaces

If you have reason to do some work on your temporary tablespaces, the following code may help.


-- Create the new temp tablespace.
CREATE TEMPORARY TABLESPACE temp2
TEMPFILE '/u01/oradata/temp02.dbf' SIZE 10M
AUTOEXTEND ON NEXT 1M MAXSIZE UNLIMITED
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M;

-- Make this the default temp tablespace.
ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp2;

-- Drop the original temp tablespace.
DROP TABLESPACE temp INCLUDING CONTENTS AND DATAFILES;

-- Create the original tablespace again.
CREATE TEMPORARY TABLESPACE temp
TEMPFILE '/u01/oradata/temp01.dbf' SIZE 10M
AUTOEXTEND ON NEXT 1M MAXSIZE UNLIMITED
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M;

-- Make this the default temp tablespace.
ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp;

-- Drop the unwanted second temp tablespace.
DROP TABLESPACE temp2 INCLUDING CONTENTS AND DATAFILES;

-- If you have a temporary tablespace without a datafile as
-- sometimes happens with an RMAN restore, this will add
-- a datafile to the tablespace.
ALTER TABLESPACE TEMP
ADD TEMPFILE '/u01/oradata/temp01.dbf' SIZE 10000M
AUTOEXTEND ON NEXT 8K MAXSIZE UNLIMITED;



Keywords: oracle temp tablespace database

Wednesday, 1 January 2014

Write-Host Considered Harmful

I read an interesting article written by Jeffrey Snover on the topic of Write-Host vs Write-Output. The article can be seen here.

In a nutshell:
The correct cmdlet to use is Write-Output. Using Write-Output will display the results to the screen when you run you script by itself but, it will also allow your script to be used in a pipeline (or foreach loop) and have the results used by other scripts/cmdlets.

See also


Why I Use Write-Host In PowerShell
This article gives some of the benefits of using Write-Host cmdlet.



Keywords: powershell write-host write-output

PowerShell enumerated types

The following code shows how to create your own enumerated types and a possible way of using the type.

$myenum = "
   Namespace myspace
   {
      public enum cards
      {
         hearts,
         clubs,
         diamonds,
         spades
      }
   }
";

try {
  [myspace.cards]
} catch {
  Add-Type -TypeDefinition $myenum -Language CSharpVersion3;
}

Write-Host "Assigning fred an enum value";
$fred=[myspace.cards]::hearts;

switch ($fred)
{
    ([myspace.cards]::hearts) {"Fred is now hearts"; Break}
    ([myspace.cards]::clubs) {"Fred is now clubs"; Break}
    ([myspace.cards]::diamonds) {"Fred is now diamonds"; Break}
    ([myspace.cards]::spades) {"Fred is now spades"; Break}
}

Write-Host "All done now!";
The try/catch block is used to avoid the error: Add-Type : Cannot add type. The type name 'myspace.cards' already exists. At line:1 char:1 + Add-Type -TypeDefinition $myenum -Language CSharpVersion3; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (myspace.cards:String) [Add-Type], Exception + FullyQualifiedErrorId : TYPE_ALREADY_EXISTS,Microsoft.PowerShell.Commands.AddTypeCommand if the assembly is already loaded. A namespace is used in the creation of this enum because as the documentation reminds us:
Include a namespace declaration in your type definition. If you omit the namespace declaration, your type might have the same name as another type or the shortcut for another type, causing an unintentional overwrite. For example, if you define a type called "Exception", scripts that use Exception" as the shortcut for System.Exception will fail.


The following code can be used to look at the definitions for the enumerated type.

foreach ($m in [System.Enum]::GetValues([ConsoleColor]))
{ Write-Host ([int]$m): $m }


Keywords: powershell enum namespace

Loaded Assemblies

Use the following code to get a list PowerShell loaded assemblies.


$m = [System.AppDomain]::CurrentDomain.GetAssemblies();
$m.getName();

See also

GetAssemblies Method



Keywords: powershell assembly assemblies

PowerShell parameters

The following code shows two ways in PowerShell can check whether an optional parameter has been used or not.

This could be used in situations where most of the time the parameter is not used and on odd occasions we decide to use the parameter.

Of course, there are other ways in which we can check, but this is also a reminder of two ways to achieve this.




function foo {

[cmdletbinding()]
Param (
        [parameter(Mandatory=$false)]
        [String]
        $Param
      ) #end param

   Write-Host "This is function foo";

   # Method 1
   if ($Param) {
      Write-Host "(1)Parameter is use is: $Param";
   } else {
      Write-Host "No parameter used at one";
   }
   # Method 2
   if ($PSBoundParameters['Param']) {
      Write-Host "(2)Parameter is use is: $Param";
   } else {
      Write-Host "No parameter used at two";
   }

} #end of foo

foo some_info ;


Keywords: powershell parameters check