oracle sql plus 假脱机
我正在使用 sql plus 执行查询(选择)并使用 spool 选项将结果转储到文件中。 我有大约 1400 万行,转储大约需要 12 分钟。 我想知道是否有什么东西可以让转储更快?
下面是我的 sql plus 选项:
whenever sqlerror exit sql.sqlcode
set pagesize 0
set linesize 410
SET trimspool ON
set heading on
set feedback off
set echo off
set termout off
spool file_to_dump_into.txt
select * from mytable;
谢谢。
I'm using sql plus to execute a query (a select) and dump the result into a file, using spool option.
I have about 14 millions lines, and it takes about 12 minutes to do the dump.
I was wondering if there is something to make the dump faster?
Here below my sql plus options:
whenever sqlerror exit sql.sqlcode
set pagesize 0
set linesize 410
SET trimspool ON
set heading on
set feedback off
set echo off
set termout off
spool file_to_dump_into.txt
select * from mytable;
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您是否正在连接 &分隔列,还是导出固定宽度?
请参阅有关SQL*Plus 脚本调整。针对您的脚本,以下是一些可能的加速方法:
希望这有帮助!
Are you concatenating & delimiting your columns, or are you exporting fixed-width?
See this documentation on SQL*Plus Script Tuning. Specific to your script, here are a few possible ways to speed it up:
Hope this helps!
您可能会发现使用 UTL_FILE 更快,但可能也没有那么快。
在我的测试中,它在处理大约 20k 行时稍微快一些,但超过 1400 万行时,它可能是值得的。
我相信,如果你想比这更快,那么要走的路就是 pro*c.. 但我还没有进入这个领域,所以不能给出真正的建议。
结果。顶部结果仅来自 sqlplus,底部使用 UTL_FILE
You might find it quicker to use UTL_FILE, but probably not that much faster.
in my test it was slightly faster over about 20k of rows, blow that out over 14 million though and it might be worth it.
I believe if you want to get any quicker than this, the way to go would be pro*c.. but I haven't got into that, so can't really advise.
The results. The top result being from sqlplus only, the bottom using UTL_FILE
对于典型的查询,
14M
记录至少需要数百兆字节的数据才能从服务器中获取、通过连接传递并保存到磁盘。鉴于此,
12
分钟对我来说听起来并不算太多。但是,您的查询仍然有可能得到优化。您可以将其发布到这里吗?
With a typical query,
14M
records is at least several hundred megabytes of data to fetch out of the server, pass across the connection and save to the disk.Given this,
12
minutes does not sound too much to me.However, it is still possible that your query can be optimized. Could you please post it here?
那么这是通过网络进行的还是您已登录到拥有数据库的盒子中?如果您有访问权限,也许您可以在数据库所在的机器上运行 sqlplus 会话并压缩文件,然后将文件发送到本地计算机。通过网络发送大文件可能比发送数百万条较小的记录更快。当然,这不会使它变得非常快,但可能会节省一些时间。
另外,有了这么多数据,您真的需要将其存储到文件中吗?你可以做出口吗?
So is this going over the wire or are you logged into the box that has the database? If you have access, maybe you can run your sqlplus session on the box where the database lives and zip the file up then send the file to your local machine. It might be faster to send a big file over the wire instead of sending millions of smaller records. Of course this won't make it super fast, but might shave some time off.
Also with that much data do you really need to spool it to file? Can you do an export instead?
您可以通过添加到脚本来启用输出缓冲
,但结果取决于您的操作系统。
You can enable output buffering by adding to you script
But result depends on your OS.
当从 SQL*Plus 中的查询中获取大量结果时,我发现需要花费大量时间的一件事是数据的实际显示。如果您要将数据假脱机到文件中,则可以
SET TERMOUT OFF
,并且查询运行得更快,因为它不必花费时间将其写入屏幕。When getting a lot of results from a query in SQL*Plus, I've found that one thing that takes a lot of time is the actual displaying of the data. If you're spooling the data to a file, you can
SET TERMOUT OFF
, and the query runs much faster since it doesn't have to spend the time to write it to the screen.Tom Kyte 是一位真正的大师,可以提供一些选项。
Some options are available from Tom Kyte, who is a real guru.