DB2创建数据库示例
DB2创建数据库示例,做完离线备份后,建议做一次在线备份(不确定是不是必须,但是正好可以测试是否能在线备份)在做以上操作时,
1 创建连接用户
mkuser id=1028 pgrp=db2user1 groups=db2user1 home=/home/fmusx core=-1 data=491519 stack=32767 rss=-1 fsize=-1 fmusx
2 创建开发数据库
db2 create database SX3 AUTOMATIC STORAGE YES ON /db2fs/sx2data DBPATH ON /db2fs/sx2 USING CODESET GBK TERRITORY CN
3 创建缓冲池
db2 create bufferpool SX_16K IMMEDIATE SIZE AUTOMATIC PAGESIZE 16K
db2 create bufferpool SX_32K IMMEDIATE SIZE AUTOMATIC PAGESIZE 32K
4 创建系统表空间
db2 CREATE SYSTEM TEMPORARY TABLESPACE TEMPSPACE16 PAGESIZE 16K BUFFERPOOL SX_16K NO FILE SYSTEM CACHING
db2 CREATE SYSTEM TEMPORARY TABLESPACE TEMPSPACE32 PAGESIZE 32K BUFFERPOOL SX_32K NO FILE SYSTEM CACHING
db2 CREATE USER TEMPORARY TABLESPACE temp16k PAGESIZE 16K BUFFERPOOL SX_16K NO FILE SYSTEM CACHING
db2 CREATE USER TEMPORARY TABLESPACE temp32k PAGESIZE 32K BUFFERPOOL SX_32K NO FILE SYSTEM CACHING
db2 GRANT USE OF TABLESPACE "temp16k" TO fmusx
db2 GRANT USE OF TABLESPACE "temp32k" TO fmusx
5 创建用户表空间
db2 create LARGE tablespace FMUSX32K_D PAGESIZE 32K BUFFERPOOL SX_32K NO FILE SYSTEM CACHING
db2 create LARGE tablespace FMUSX32K_I PAGESIZE 32K BUFFERPOOL SX_32K NO FILE SYSTEM CACHING
db2 GRANT USE OF TABLESPACE FMUSX32K_D TO fmusx
db2 GRANT USE OF TABLESPACE FMUSX32K_I TO fmusx
6 删除默认用户表空间
$ db2 drop tablespace USERSPACE1
DB20000I The SQL command completed successfully.
7 设置归档模式
db2 update db cfg using LOGFILSIZ 102400
db2 update db cfg using LOGPRIMARY 20
db2 update db cfg using LOGSECOND 50
db2 update db cfg using LOGARCHMETH1 disk:/db2fs/db2backup/archive_log/sx3/ immediate
$ db2 update db cfg using LOGFILSIZ 102400
db2 update db cfg using LOGPRIMARY 20
db2 update db cfg using LOGSECOND 50
db2 update db cfg using LOGARCHMETH1 disk:/db2fs/db2backup/archive_log/sx3/ immediate
DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.
SQL1363W Database must be deactivated and reactivated before the changes to
one or more of the configuration parameters will be effective.
$ db2 update db cfg using LOGPRIMARY 20
DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.
SQL1363W Database must be deactivated and reactivated before the changes to
one or more of the configuration parameters will be effective.
$ db2 update db cfg using LOGSECOND 50
DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.
$ db2 update db cfg using LOGARCHMETH1 disk:/db2fs/db2backup/archive_log/sx3/ immediate
DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.
SQL1363W Database must be deactivated and reactivated before the changes to
one or more of the configuration parameters will be effective.
注:a.归档目录一定要先创建,否则会报错
b.除LOGSECOND外,,其他参数都需要重启数据库才能生效(或者直接重启instance)
8. 备份数据库
将数据库修改为归档模式后,必须先离线备份数据库,否则整个数据库的状态将为backup pending,无法访问。
$ db2 backup db sx3 to /db2fs/db2backup/sx3backup
Backup successful. The timestamp for this backup image is : 20120817225640
备注:做完离线备份后,建议做一次在线备份(不确定是不是必须,但是正好可以测试是否能在线备份)
$ db2 backup db sx3 online to /db2fs/db2backup/sx3backup include logs
Backup successful. The timestamp for this backup image is : 20120817225824
备注:在做以上操作时,为防止其他非本地应用连接数据库,可以将instance的协议注销,类似于Oracle中关闭监听器的操作。
$ db2set -all
[i] DB2_DATABASE_CF_MEMORY=-1
[i] DB2_COMPATIBILITY_VECTOR=ORA
[i] DB2RSHCMD=/bin/ssh
[i] DB2COUNTRY=86
[i] DB2COMM=TCPIP
[i] DB2CODEPAGE=1386
[i] DB2AUTOSTART=NO
[g] DB2SYSTEM=SXYCDBM0
[g] DB2INSTDEF=db2sdin1
关闭连接端口
$ db2set DB2COMM=
$ db2set -all
[i] DB2_DATABASE_CF_MEMORY=-1
[i] DB2_COMPATIBILITY_VECTOR=ORA
[i] DB2RSHCMD=/bin/ssh
[i] DB2COUNTRY=86
[i] DB2CODEPAGE=1386
[i] DB2AUTOSTART=NO
[g] DB2SYSTEM=SXYCDBM0
[g] DB2INSTDEF=db2sdin1
备注:这些有“[i]”标识的参数为实例级参数,需要重启实例才能生效

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The amount of memory required by Oracle depends on database size, activity level, and required performance level: for storing data buffers, index buffers, executing SQL statements, and managing the data dictionary cache. The exact amount is affected by database size, activity level, and required performance level. Best practices include setting the appropriate SGA size, sizing SGA components, using AMM, and monitoring memory usage.

Oracle database server hardware configuration requirements: Processor: multi-core, with a main frequency of at least 2.5 GHz. For large databases, 32 cores or more are recommended. Memory: At least 8GB for small databases, 16-64GB for medium sizes, up to 512GB or more for large databases or heavy workloads. Storage: SSD or NVMe disks, RAID arrays for redundancy and performance. Network: High-speed network (10GbE or higher), dedicated network card, low-latency network. Others: Stable power supply, redundant components, compatible operating system and software, heat dissipation and cooling system.

The amount of memory required for an Oracle database depends on the database size, workload type, and number of concurrent users. General recommendations: Small databases: 16-32 GB, Medium databases: 32-64 GB, Large databases: 64 GB or more. Other factors to consider include database version, memory optimization options, virtualization, and best practices (monitor memory usage, adjust allocations).

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

How to integrate GoWebSocket with a database: Set up a database connection: Use the database/sql package to connect to the database. Store WebSocket messages to the database: Use the INSERT statement to insert the message into the database. Retrieve WebSocket messages from the database: Use the SELECT statement to retrieve messages from the database.
