Oracle新建用户、角色,授权,建表空间的sql语句
2012-08-13 15:22
671 查看
操作背景
某个目录文件大概上千万个,系统ls执行非常慢,甚无执行了10几个小时后会自动中断
恰好网上有人写了一个C程序来处理这个问题,代码如下
#define _GNU_SOURCE
#include <dirent.h> /* Defines DT_* constants */
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#define handle_error(msg) \
do { perror(msg); exit(EXIT_FAILURE); } while (0)
struct linux_dirent {
long d_ino;
off_t d_off;
unsigned short d_reclen;
char d_name[];
};
#define BUF_SIZE 1024
int
main(int argc, char *argv[])
{
int fd, nread;
char buf[BUF_SIZE];
struct linux_dirent *d;
int bpos;
char d_type;
fd = open(argc > 1 ? argv[1] : ".", O_RDONLY | O_DIRECTORY);
if (fd == -1)
handle_error("open");
for ( ; ; ) {
nread = syscall(SYS_getdents, fd, buf, BUF_SIZE);
if (nread == -1)
handle_error("getdents");
if (nread == 0)
break;
printf("--------------- nread=%d ---------------\n", nread);
printf("i-node# file type d_reclen d_off d_name\n");
for (bpos = 0; bpos < nread;) {
d = (struct linux_dirent *) (buf + bpos);
printf("%8ld ", d->d_ino);
d_type = *(buf + bpos + d->d_reclen - 1);
printf("%-10s ", (d_type == DT_REG) ? "regular" :
(d_type == DT_DIR) ? "directory" :
(d_type == DT_FIFO) ? "FIFO" :
(d_type == DT_SOCK) ? "socket" :
(d_type == DT_LNK) ? "symlink" :
(d_type == DT_BLK) ? "block dev" :
(d_type == DT_CHR) ? "char dev" : "???");
printf("%4d %10lld %s\n", d->d_reclen,
(long long) d->d_off, d->d_name);
bpos += d->d_reclen;
}
}
exit(EXIT_SUCCESS);
}
将代码放入list.c文件
然后执行gcc list.c -o list
执行./list <目录>即可
当然,以上代码为原始代码,速度还是不太理想,下面是改进版:
#define _GNU_SOURCE
#include <dirent.h> /* Defines DT_* constants */
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#define handle_error(msg) \
do { perror(msg); exit(EXIT_FAILURE); } while (0)
struct linux_dirent {
long d_ino;
off_t d_off;
unsigned short d_reclen;
char d_name[];
};
// #define BUF_SIZE 1024
#define BUF_SIZE 1024*1024*9
int
main(int argc, char *argv[])
{
int fd, nread;
char buf[BUF_SIZE];
struct linux_dirent *d;
int bpos;
char d_type;
fd = open(argc > 1 ? argv[1] : ".", O_RDONLY | O_DIRECTORY);
if (fd == -1)
handle_error("open");
for ( ; ; ) {
nread = syscall(SYS_getdents, fd, buf, BUF_SIZE);
if (nread == -1)
handle_error("getdents");
if (nread == 0)
break;
// printf("--------------- nread=%d ---------------\n", nread);
// printf("i-node# file type d_reclen d_off d_name\n");
for (bpos = 0; bpos < nread;) {
d = (struct linux_dirent *) (buf + bpos);
// printf("%8ld ", d->d_ino);
d_type = *(buf + bpos + d->d_reclen - 1);
// printf("%-10s ", (d_type == DT_REG) ? "regular" :
// (d_type == DT_DIR) ? "directory" :
// (d_type == DT_FIFO) ? "FIFO" :
// (d_type == DT_SOCK) ? "socket" :
// (d_type == DT_LNK) ? "symlink" :
// (d_type == DT_BLK) ? "block dev" :
// (d_type == DT_CHR) ? "char dev" : "???");
// printf("%4d %10lld %s\n", d->d_reclen,
// (long long) d->d_off, d->d_name);
if(d->d_ino) printf("%s\n ", (char *) d->d_name);
bpos += d->d_reclen;
}
}
exit(EXIT_SUCCESS);
}
某个目录文件大概上千万个,系统ls执行非常慢,甚无执行了10几个小时后会自动中断
恰好网上有人写了一个C程序来处理这个问题,代码如下
#define _GNU_SOURCE
#include <dirent.h> /* Defines DT_* constants */
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#define handle_error(msg) \
do { perror(msg); exit(EXIT_FAILURE); } while (0)
struct linux_dirent {
long d_ino;
off_t d_off;
unsigned short d_reclen;
char d_name[];
};
#define BUF_SIZE 1024
int
main(int argc, char *argv[])
{
int fd, nread;
char buf[BUF_SIZE];
struct linux_dirent *d;
int bpos;
char d_type;
fd = open(argc > 1 ? argv[1] : ".", O_RDONLY | O_DIRECTORY);
if (fd == -1)
handle_error("open");
for ( ; ; ) {
nread = syscall(SYS_getdents, fd, buf, BUF_SIZE);
if (nread == -1)
handle_error("getdents");
if (nread == 0)
break;
printf("--------------- nread=%d ---------------\n", nread);
printf("i-node# file type d_reclen d_off d_name\n");
for (bpos = 0; bpos < nread;) {
d = (struct linux_dirent *) (buf + bpos);
printf("%8ld ", d->d_ino);
d_type = *(buf + bpos + d->d_reclen - 1);
printf("%-10s ", (d_type == DT_REG) ? "regular" :
(d_type == DT_DIR) ? "directory" :
(d_type == DT_FIFO) ? "FIFO" :
(d_type == DT_SOCK) ? "socket" :
(d_type == DT_LNK) ? "symlink" :
(d_type == DT_BLK) ? "block dev" :
(d_type == DT_CHR) ? "char dev" : "???");
printf("%4d %10lld %s\n", d->d_reclen,
(long long) d->d_off, d->d_name);
bpos += d->d_reclen;
}
}
exit(EXIT_SUCCESS);
}
将代码放入list.c文件
然后执行gcc list.c -o list
执行./list <目录>即可
当然,以上代码为原始代码,速度还是不太理想,下面是改进版:
#define _GNU_SOURCE
#include <dirent.h> /* Defines DT_* constants */
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#define handle_error(msg) \
do { perror(msg); exit(EXIT_FAILURE); } while (0)
struct linux_dirent {
long d_ino;
off_t d_off;
unsigned short d_reclen;
char d_name[];
};
// #define BUF_SIZE 1024
#define BUF_SIZE 1024*1024*9
int
main(int argc, char *argv[])
{
int fd, nread;
char buf[BUF_SIZE];
struct linux_dirent *d;
int bpos;
char d_type;
fd = open(argc > 1 ? argv[1] : ".", O_RDONLY | O_DIRECTORY);
if (fd == -1)
handle_error("open");
for ( ; ; ) {
nread = syscall(SYS_getdents, fd, buf, BUF_SIZE);
if (nread == -1)
handle_error("getdents");
if (nread == 0)
break;
// printf("--------------- nread=%d ---------------\n", nread);
// printf("i-node# file type d_reclen d_off d_name\n");
for (bpos = 0; bpos < nread;) {
d = (struct linux_dirent *) (buf + bpos);
// printf("%8ld ", d->d_ino);
d_type = *(buf + bpos + d->d_reclen - 1);
// printf("%-10s ", (d_type == DT_REG) ? "regular" :
// (d_type == DT_DIR) ? "directory" :
// (d_type == DT_FIFO) ? "FIFO" :
// (d_type == DT_SOCK) ? "socket" :
// (d_type == DT_LNK) ? "symlink" :
// (d_type == DT_BLK) ? "block dev" :
// (d_type == DT_CHR) ? "char dev" : "???");
// printf("%4d %10lld %s\n", d->d_reclen,
// (long long) d->d_off, d->d_name);
if(d->d_ino) printf("%s\n ", (char *) d->d_name);
bpos += d->d_reclen;
}
}
exit(EXIT_SUCCESS);
}
相关文章推荐
- Oracle新建用户、角色,授权,建表空间的sql语句
- Oracle新建用户、角色,授权,建表空间的sql语句
- Oracle常用命令_查看用户_新建user_连接user_授权user_版本_表空间查看_控制文件_日志_sql语句
- Oracle新建用户、角色,授权,建表空间(转)
- Oracle新建用户、角色,授权,建表空间
- Oracle 新建用户、角色、授权、建表空间
- Oracle sql语句创建表空间、数据库、用户及授权
- Oracle新建用户、角色,授权,建表空间
- oracle 创建表空间、用户、授权的详细操作sql语句
- Oracle新建用户、角色,授权,建表空间
- Oracle新建用户、角色,授权,建表空间
- Oracle新建用户,授权,建表空间语句
- oracle新建用户,授权,建表空间语句
- Oracle新建用户、角色,授权,建表空间
- oracle新建用户,授权,建表空间语句
- Oracle创建表空间、创建用户以及授权、查看权限常用sql语句
- Oracle创建表空间,用户,授权,导入.sql/.dem文件语句
- Oracle新建用户、角色,授权,建表空间
- Oracle新建用户、角色,授权,建表空间
- Oracle新建用户、角色,授权,建表空间